Guest User

Untitled

a guest
Dec 11th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. int firstButton = 2;
  2. int secondButton = 3;
  3. int thirdButton = 4;
  4. int fourthButton = 5;
  5.  
  6. unsigned long startMillis;
  7. unsigned long currentMillis;
  8. const unsigned long period = 1000;
  9.  
  10. void setup() {
  11.  
  12. const int redLEDPin = 10;
  13. const int greenLEDPin = 9;
  14.  
  15. const int secondGreenLEDPin = 11;
  16. const int secondRedLEDPin = 12;
  17.  
  18. const int thirdGreenLEDPin = 8;
  19. const int thirdRedLEDPin = 13;
  20.  
  21. const int fourthRedLEDPin = 6;
  22. const int fourthGreenLEDPin = 7;
  23.  
  24. pinMode(9, OUTPUT); // First blue light
  25. pinMode(10, OUTPUT); // first green light
  26. pinMode(2, INPUT); // first button
  27.  
  28. pinMode(12, OUTPUT); // second green light
  29. pinMode(11, OUTPUT); // second blue light
  30. pinMode(3, INPUT); // Second button
  31.  
  32. pinMode(13, OUTPUT); // third green light
  33. pinMode(8, OUTPUT); // third blue light
  34. pinMode(4, INPUT); // Third button
  35.  
  36. pinMode(6, OUTPUT); // Fourth green light
  37. pinMode(7, OUTPUT); // Fourth blue light
  38. pinMode(5, INPUT); // fourth button
  39.  
  40. pinMode(1, OUTPUT); // Sound
  41.  
  42. }
  43.  
  44.  
  45.  
  46. void loop() {
  47.  
  48. int whichLight(random(1,5));
  49. int currentMillis = millis();
  50.  
  51. if (whichLight == 1) {
  52. firstButton = digitalRead(2);
  53. int lightOne(random(1, 3));
  54. if (lightOne == 1) {
  55. digitalWrite(10, HIGH); // first green light
  56. }
  57. else {
  58. digitalWrite(9, HIGH); // first blue light
  59. tone(1, 880, 50);
  60. }
  61. if (firstButton == HIGH) {
  62. digitalWrite(10, LOW);
  63. delay(150);
  64. }
  65. delay(1000);
  66. digitalWrite(10, LOW);
  67. digitalWrite(9, LOW);
  68. delay(50);
  69. }
  70.  
  71.  
  72. else if (whichLight == 2) {
  73. secondButton = digitalRead(3);
  74. int lightSecond(random(1, 3));
  75. if (lightSecond == 1) {
  76. digitalWrite(12, HIGH); // second green light
  77. }
  78. else {
  79. digitalWrite(11, HIGH); // second blue light
  80. tone(1, 880, 50);
  81. }
  82. if (secondButton == HIGH) {
  83. digitalWrite(12, LOW);
  84. delay(150);
  85. }
  86.  
  87. delay(1000);
  88. digitalWrite(12, LOW);
  89. digitalWrite(11, LOW);
  90. delay(50);
  91. }
  92.  
  93.  
  94. else if (whichLight == 3) {
  95. thirdButton = digitalRead(4);
  96. int lightThird(random(1, 3));
  97. if (lightThird == 1) {
  98. digitalWrite(13, HIGH); // third green light
  99. }
  100. else {
  101. digitalWrite(8, HIGH); // third blue light
  102. tone(1, 880, 50);
  103. }
  104. if (thirdButton == HIGH) {
  105. digitalWrite(13, LOW);
  106. delay(150);
  107. }
  108.  
  109. delay(1000);
  110. digitalWrite(13, LOW);
  111. digitalWrite(8, LOW);
  112. delay(50);
  113. }
  114.  
  115.  
  116. else if(whichLight == 4) {
  117. fourthButton = digitalRead(5);
  118. int lightFourth(random(1, 3));
  119. if (lightFourth == 1){
  120. digitalWrite(6, HIGH); // fourth green light
  121. }
  122. else {
  123. digitalWrite(7, HIGH); // fourth blue light
  124. tone(1, 880, 50);
  125. }
  126. if (fourthButton == HIGH) {
  127. digitalWrite(6, LOW);
  128. delay(150);
  129. }
  130. delay(1000);
  131. digitalWrite(7, LOW);
  132. digitalWrite(6, LOW);
  133. delay(50);
  134.  
  135. }
  136. }
Add Comment
Please, Sign In to add comment