esha492

Untitled

Sep 14th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. const int LedPinGreen = 11;
  2. const int LedPinRed = 10;
  3. const int Button = 12;
  4. boolean ReadValue;
  5. boolean LastValue;
  6. int counter=0;
  7.  
  8. void setup()
  9. {
  10. pinMode (LedPinGreen, OUTPUT);
  11. pinMode (LedPinRed, OUTPUT);
  12. pinMode (Button, INPUT);
  13. Serial.begin (9600);
  14. }
  15.  
  16. boolean debounce(boolean last)
  17. {
  18.   boolean current = digitalRead(Button);
  19.   if (last != current)
  20.   {
  21.     delay(5);
  22.     current = digitalRead(Button);
  23.   }
  24.   return current;
  25. }
  26.  
  27. void loop()
  28. {
  29.   ReadValue = debounce (LastValue);
  30.   if (LastValue == LOW && ReadValue ==HIGH)
  31.   {
  32.     counter++;
  33.     Serial.println(counter);
  34.   }
  35.   if (counter== 1||counter == 4)
  36. {
  37.  
  38. digitalWrite (LedPinRed, HIGH);
  39. digitalWrite (LedPinGreen, LOW);
  40.   
  41. }
  42. if (counter==2)
  43. {digitalWrite (LedPinRed, LOW);
  44. digitalWrite (LedPinGreen, HIGH);
  45. }
  46.  
  47. if (counter == 3)
  48.  
  49. {
  50. digitalWrite (LedPinRed, HIGH);
  51. digitalWrite (LedPinGreen, HIGH);
  52. }
  53.  
  54. if (counter == 5)
  55.  
  56. {
  57. digitalWrite (LedPinRed, LOW);
  58. digitalWrite (LedPinGreen, LOW);
  59. counter=0;
  60. }
  61. LastValue = ReadValue;
  62. }
Add Comment
Please, Sign In to add comment