Advertisement
coltonspastebin

Circus LED DICE on cardboard

Jan 9th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. const int button = 12;
  2. const int pin1 = 3;//middle led
  3. const int pin2 = 4;//middle layer outer two
  4. const int pin3 = 6;//bottom layer
  5. const int pin4 = 5;//top layer
  6. int randi;
  7. int readValue = 0;
  8. boolean lastbutton = false;
  9. boolean currentbutton = false;
  10.  
  11. void setup()
  12. {
  13. randomSeed(A0);//allows me to give a range instead of being limited to one number
  14. pinMode (button, INPUT);
  15. pinMode (pin1, OUTPUT);
  16. pinMode (pin2, OUTPUT);
  17. pinMode (pin3, OUTPUT);
  18. pinMode (pin4, OUTPUT);
  19. Serial.begin (9600);
  20. }
  21. boolean debounce (boolean lastbutton)
  22. {
  23. boolean currentbutton = digitalRead (button);
  24. if (lastbutton != currentbutton)
  25. {
  26. delay (5);
  27. currentbutton = digitalRead (button);
  28. }
  29. return currentbutton;
  30. }
  31.  
  32. void loop()
  33. {
  34. currentbutton = debounce (lastbutton);//this is used so that the LED will stay on without having to hold down the button
  35. if (currentbutton == true && lastbutton == false)
  36. {
  37. randi = random (1,7);//this gives me a random number from 1-7 (1 is included but 7 is not): could also do random (6)+1
  38. Serial.println (randi);
  39. digitalWrite (pin1, HIGH);
  40. digitalWrite (pin2, HIGH);
  41. digitalWrite (pin3, HIGH);
  42. digitalWrite (pin4, HIGH);
  43. delay (200);
  44. digitalWrite (pin1, LOW);
  45. digitalWrite (pin2, LOW);
  46. digitalWrite (pin3, LOW);
  47. digitalWrite (pin4, LOW);
  48. delay (50);
  49. digitalWrite (pin1, HIGH);
  50. digitalWrite (pin2, HIGH);
  51. digitalWrite (pin3, HIGH);
  52. digitalWrite (pin4, HIGH);
  53. delay (200);
  54. digitalWrite (pin1, LOW);
  55. digitalWrite (pin2, LOW);
  56. digitalWrite (pin3, LOW);
  57. digitalWrite (pin4, LOW);
  58. delay (50);
  59. digitalWrite (pin1, HIGH);
  60. digitalWrite (pin2, HIGH);
  61. digitalWrite (pin3, HIGH);
  62. digitalWrite (pin4, HIGH);
  63. delay (200);
  64. digitalWrite (pin1, LOW);
  65. digitalWrite (pin2, LOW);
  66. digitalWrite (pin3, LOW);
  67. digitalWrite (pin4, LOW);
  68. delay (50);
  69. digitalWrite (pin1, HIGH);
  70. digitalWrite (pin2, HIGH);
  71. digitalWrite (pin3, HIGH);
  72. digitalWrite (pin4, HIGH);
  73. delay (200);
  74. digitalWrite (pin1, LOW);
  75. digitalWrite (pin2, LOW);
  76. digitalWrite (pin3, LOW);
  77. digitalWrite (pin4, LOW);
  78. }
  79. switch (randi)//this gives me cases that correlate to the number generated by the rani
  80. {
  81. case 1://if number is 1 only the middle LED will turn on
  82. digitalWrite (pin1, HIGH);
  83. break;
  84. case 2://if number is 2 the middle outside LED's will turn on
  85. digitalWrite (pin2, HIGH);
  86. break;
  87. case 3://if number is 3 the middle row LED's will turn on
  88. digitalWrite (pin1, HIGH);
  89. digitalWrite (pin2, HIGH);
  90. break;
  91. case 4: //if number is 4 the top and bottom layers of LED's will turn on
  92. digitalWrite (pin3, HIGH);
  93. digitalWrite (pin4, HIGH);
  94. break;
  95. case 5://if number is 5 the top and bottom as well as the middle LED will turn on
  96. digitalWrite (pin3, HIGH);
  97. digitalWrite (pin4, HIGH);
  98. digitalWrite (pin1, HIGH);
  99. break;
  100. case 6://if number is 6 every LED will be on EXCEPT for the middle LED
  101. digitalWrite (pin3, HIGH);
  102. digitalWrite (pin4, HIGH);
  103. digitalWrite (pin2, HIGH);
  104. break;
  105. default://if there is no number then no LED will be turned on
  106. digitalWrite (pin1, LOW);
  107. digitalWrite (pin2, LOW);
  108. digitalWrite (pin3, LOW);
  109. digitalWrite (pin4, LOW);
  110. break;
  111.  
  112. }
  113. lastbutton = currentbutton;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement