britneybeatey

Random

Jun 12th, 2017
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. /*
  2. * Britney Beatey
  3. * Version 3
  4. * Random
  5. */
  6. const int pinLed1 = 7;
  7. const int pinLed2 = 5;
  8. const int pinLed3 = 3;
  9. const int pinButt = 10;
  10. boolean buttDown = 0;
  11. boolean ledOn = 0;
  12. boolean lastButt = 0;
  13. int counter = 0;
  14.  
  15.  
  16. void setup() {
  17. // put your setup code here, to run once:
  18. pinMode (pinLed1, OUTPUT);
  19. pinMode (pinLed2, OUTPUT);
  20. pinMode (pinLed3, OUTPUT);
  21. pinMode (pinButt, INPUT);
  22.  
  23. Serial.begin (9600);
  24. randomSeed (analogRead(A0));
  25.  
  26. digitalWrite (pinLed1, HIGH);
  27. digitalWrite (pinLed2, HIGH);
  28. digitalWrite (pinLed3, HIGH);
  29. delay (500);
  30. digitalWrite (pinLed1, LOW);
  31. digitalWrite (pinLed2, LOW);
  32. digitalWrite (pinLed3, LOW);
  33. }
  34.  
  35. void loop() {
  36. // put your main code here, to run repeatedly:
  37. buttDown = debounce (lastButt);
  38. Serial.println (buttDown);
  39.  
  40. if (lastButt == LOW && buttDown == HIGH) // Checks case the button has been pressed
  41. {
  42. counter = random(1,5);
  43. }
  44. switch (counter)
  45. {
  46.  
  47. case 1:
  48.  
  49. digitalWrite (pinLed1, HIGH);
  50. digitalWrite (pinLed2, LOW);
  51. digitalWrite (pinLed3, LOW);
  52. break;
  53.  
  54. case 2:
  55.  
  56. digitalWrite (pinLed1, HIGH);
  57. digitalWrite (pinLed2, HIGH);
  58. digitalWrite (pinLed3, LOW);
  59. break;
  60.  
  61. case 3:
  62.  
  63. digitalWrite (pinLed1, HIGH);
  64. digitalWrite (pinLed2, HIGH);
  65. digitalWrite (pinLed3, HIGH);
  66. break;
  67.  
  68. case 4:
  69.  
  70. digitalWrite (pinLed1, LOW);
  71. digitalWrite (pinLed2, LOW);
  72. digitalWrite (pinLed3, LOW);
  73. counter = 0;
  74. break;
  75. default:
  76. Serial.println("You are out of space");
  77.  
  78. lastButt = buttDown;
  79.  
  80. }
  81.  
  82. }
  83.  
  84. boolean debounce(boolean last)
  85. {
  86. boolean current = digitalRead(pinButt);
  87. if (last != current)
  88. {
  89. delay(5);
  90. current = digitalRead(pinButt);
  91. }
  92. return current;
  93. }
Add Comment
Please, Sign In to add comment