Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int INT = 2;
- int BTN1 = 6;
- int BTN2 = 7;
- volatile int count = 0;
- volatile bool push = false;
- void readBtn() {
- int b1 = digitalRead(BTN1);
- int b2 = digitalRead(BTN2);
- if (b1 == 0) {
- count++;
- digitalWrite(LED_BUILTIN, HIGH);
- push = true;
- }
- else if (b2 == 0) {
- count--;
- digitalWrite(LED_BUILTIN, LOW);
- push = true;
- }
- else {
- Serial.println("Glitch!");
- }
- }
- void setup() {
- // put your setup code here, to run once:
- pinMode(INT, INPUT);
- pinMode(BTN1, INPUT);
- pinMode(BTN2, INPUT);
- pinMode(LED_BUILTIN, OUTPUT);
- attachInterrupt(digitalPinToInterrupt(INT), readBtn, FALLING);
- Serial.begin(9600);
- count = 0;
- push = false;
- }
- void loop() {
- // put your main code here, to run repeatedly:
- if (push) {
- Serial.print("Counter: ");
- Serial.println(count);
- push = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement