Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Arduino Totalizer
- *
- * learnelectronics
- * 12 DEC 2017
- *
- * www.youtube.com/c/learnelectronics
- *
- * note: range: +/- 5-300Hz
- */
- #include <Wire.h> //I2C Driver for OLED
- #include <Adafruit_SSD1306.h> //OLED Driver
- #define OLED_RESET 4 //for oled
- Adafruit_SSD1306 display(OLED_RESET); //create instance of SS1306 called display
- long count = 0; //declare var for counting
- int flag = 0; //declare variable for stop flag
- void setup() {
- display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //start OLED @ hex addy 0x3c
- display.display(); //initialize display
- display.clearDisplay();
- pinMode(8,INPUT); //set dig pin 8 as input
- pinMode(12,INPUT_PULLUP); //set dig pin 12 as input w/internal pullup
- }
- void loop() {
- int stopnow = digitalRead(12); //check if stop switch is pressed
- if(stopnow == 0)flag = 1; //if stop switch has been pressed set flag
- int check = digitalRead(8); //check for a pulse
- if(check==1 && flag == 0)count++; // if the pulse is high AND the flag is not set increment count
- display.clearDisplay();
- display.setTextSize(3);
- display.setTextColor(WHITE);
- display.setCursor(0,0);
- display.println(count); //show the count
- display.display();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement