Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //****************************************************
- //* Arduino Tally Counter *
- //* learnelectronics *
- //* www.youtube.com/learnelectronics *
- //* *
- //* **************************************************
- #include <Wire.h> //library for the OLED on I2C
- #include <Adafruit_GFX.h> //goes with OLED driver
- #include <Adafruit_SSD1306.h> //OLED driver
- #define OLED_RESET 4 //required for oled
- Adafruit_SSD1306 display(OLED_RESET); //setup oled as "display"
- int count = 0; //initial/reset state of main variable
- int buttonState = LOW; //used to debounce the button
- long lastDebounceTime = 0; //used to debounce the button
- long debounceDelay = 500; //used to debounce the button
- void setup() {
- pinMode(2,INPUT_PULLUP); //main switch held high with internal pullup
- pinMode(4,INPUT_PULLUP); //counter reset held high blah blah
- //Serial.begin(9600); //serial comms for debugging
- display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //turn on ze bubble machine
- display.display(); //show display
- delay(500); //pause
- display.clearDisplay(); //clear display
- }
- void loop() {
- int pressed = (digitalRead(2)); //pressed is set to state of pin 2
- //Serial.println(pressed);
- // debounce routine
- if ( (millis() - lastDebounceTime) > debounceDelay) {
- //if the button was pressed
- if ( (pressed == LOW) ) {
- count++; // increment count -- ie the whole purpose for the program
- lastDebounceTime = millis(); //set the current time
- }
- }
- int setToZero = (digitalRead(4)); //did someone hit reset?
- if (setToZero == 0) count = 0; // set the count to zero
- // Serial.println(setToZero);
- //show the vaule of count on the oled
- display.clearDisplay();
- display.setTextSize(5);
- display.setTextColor(WHITE);
- display.setCursor(0,0);
- display.clearDisplay();
- display.println(count);
- display.display();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement