Advertisement
RebounD11

Diode AND interrupt

Nov 30th, 2020
1,168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. int INT = 2;
  2. int BTN1 = 6;
  3. int BTN2 = 7;
  4. volatile int count = 0;
  5. volatile bool push = false;
  6.  
  7. void readBtn() {
  8.   int b1 = digitalRead(BTN1);
  9.   int b2 = digitalRead(BTN2);
  10.   if (b1 == 0) {
  11.     count++;
  12.     digitalWrite(LED_BUILTIN, HIGH);
  13.     push = true;
  14.   }
  15.   else if (b2 == 0) {
  16.     count--;
  17.     digitalWrite(LED_BUILTIN, LOW);
  18.     push = true;
  19.   }
  20.   else {
  21.     Serial.println("Glitch!");
  22.   }
  23. }
  24.  
  25. void setup() {
  26.   // put your setup code here, to run once:
  27.   pinMode(INT, INPUT);
  28.   pinMode(BTN1, INPUT);
  29.   pinMode(BTN2, INPUT);
  30.   pinMode(LED_BUILTIN, OUTPUT);
  31.   attachInterrupt(digitalPinToInterrupt(INT), readBtn, FALLING);
  32.   Serial.begin(9600);
  33.   count = 0;
  34.   push = false;
  35. }
  36.  
  37. void loop() {
  38.   // put your main code here, to run repeatedly:
  39.   if (push) {
  40.     Serial.print("Counter: ");
  41.     Serial.println(count);
  42.     push = false;
  43.   }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement