Advertisement
kogerr19

MiniProjectPrototype3

Jun 12th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. /*
  2. * Lighting all the LED mini project prototype
  3. * Rylyn Koger
  4. * Version 2 06/09/2017
  5. *
  6. */
  7.  
  8. const int pinBlue=5;
  9. const int pinWhite=4;
  10. const int pinRed=3;
  11. const int pinButton=2;
  12. int readValue= 0;
  13. int counter=0;
  14. int currentState=0;
  15. int previousState=0;
  16. boolean flag=0;
  17. boolean lastButton=0;
  18.  
  19. void setup()
  20. {
  21. pinMode(pinBlue, OUTPUT);
  22. pinMode(pinWhite, OUTPUT);
  23. pinMode(pinRed, OUTPUT);
  24. pinMode(pinButton, INPUT);
  25. digitalWrite(pinBlue, HIGH);
  26. delay(1000);
  27. digitalWrite(pinWhite, HIGH);
  28. delay(1000);
  29. digitalWrite(pinRed, HIGH);
  30. delay(1000);
  31. digitalWrite(pinBlue, LOW);
  32. digitalWrite(pinWhite, LOW);
  33. digitalWrite(pinRed, LOW);
  34. Serial.begin(9600);
  35.  
  36. }
  37.  
  38. void loop()
  39. //Serial.print(digitalRead(pinButton);
  40. {
  41. readValue = digitalRead(pinButton);
  42. delay (5);
  43. readValue = debounce(lastButton); // will go and read the Button
  44. if (lastButton == LOW && readValue == HIGH) // Checks if the button has been pressed
  45. {
  46. counter ++;
  47. }
  48. if(counter==1)
  49. {
  50. digitalWrite (pinBlue, HIGH);
  51. digitalWrite (pinWhite, LOW);
  52. digitalWrite (pinRed, LOW);
  53. }
  54. else if(counter==2)
  55. {
  56. digitalWrite(pinBlue, LOW);
  57. digitalWrite(pinWhite, HIGH);
  58. digitalWrite(pinRed, LOW);
  59. }
  60. else if (counter==3)
  61. {
  62. digitalWrite(pinBlue, LOW);
  63. digitalWrite(pinWhite, LOW);
  64. digitalWrite(pinRed, HIGH);
  65. }
  66. else
  67. {
  68. digitalWrite(pinBlue, LOW);
  69. digitalWrite(pinWhite, LOW);
  70. digitalWrite(pinRed, LOW);
  71. counter= 0;
  72. }
  73. lastButton = readValue;
  74.  
  75. }
  76.  
  77. boolean debounce(boolean last)
  78. {
  79. boolean current = digitalRead(pinButton);
  80. if (last != current)
  81. {
  82. delay(5);
  83. current = digitalRead(pinButton);
  84. }
  85. return current;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement