esha492

2 LED function

Sep 14th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 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. if (counter==2)
  42. {digitalWrite (LedPinRed, LOW);
  43. digitalWrite (LedPinGreen, HIGH);
  44. }
  45.  
  46. if (counter == 3)
  47.  
  48. {
  49. digitalWrite (LedPinRed, HIGH);
  50. digitalWrite (LedPinGreen, HIGH);
  51. }
  52.  
  53. if (counter == 5)
  54.  
  55. {
  56. digitalWrite (LedPinRed, LOW);
  57. digitalWrite (LedPinGreen, LOW);
  58. counter=0;
  59. }
  60. LastValue = ReadValue;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment