Advertisement
GeldenGolem

2 LEDs and 5 Cases

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