Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.74 KB | None | 0 0
  1. #define PIN_DECREASE 1
  2. #define PIN_INCREASE 2
  3.  
  4. int16_t counter = 0;
  5. int8_t old_state_pin_decrease = 0;
  6. int8_t old_state_pin_increase = 0;
  7. int8_t current_state_pin_decrease = 0;
  8. int8_t current_state_pin_increase = 0;
  9.  
  10. void setup()
  11. {
  12.   pinMode(PIN_DECREASE, INPUT);
  13.   pinMode(PIN_INCREASE, INPUT);
  14. }
  15.  
  16. void loop()
  17. {
  18.    current_state_pin_decrease = digitalRead(PIN_DECREASE);
  19.    if (current_state_pin_decrease != old_state_pin_decrease)
  20.    {
  21.       counter--;
  22.       old_state_pin_decrease = current_state_pin_decrease;
  23.    }
  24.  
  25.    current_state_pin_increase = digitalRead(PIN_INCREASE);
  26.    if (current_state_pin_increase != old_state_pin_increase)
  27.    {
  28.       counter++;
  29.       old_state_pin_increase = current_state_pin_increase;
  30.    }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement