Advertisement
Guest User

4 button game buzzer

a guest
Dec 30th, 2021
7
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None
  1. // define pins to be used
  2.  
  3. int S1 = 2; //switch 1
  4.  
  5. int S2 = 3;
  6.  
  7. int S3 = 4;
  8.  
  9. int S4 = 5;
  10.  
  11. int S5 = 6;
  12.  
  13. int L1 = 7; // light 1
  14.  
  15. int L2 = 8;
  16.  
  17. int L3 = 9;
  18.  
  19. int L4 = 10;
  20.  
  21. int L5 = 11;
  22.  
  23. int B = 12; // buzzer
  24.  
  25. void setup() {
  26.  
  27. // initialize the digital pins.
  28.  
  29. // assume switches will wire from ground to input pins
  30.  
  31. pinMode(S1, INPUT_PULLUP);
  32.  
  33. pinMode(S2, INPUT_PULLUP);
  34.  
  35. pinMode(S3, INPUT_PULLUP);
  36.  
  37. pinMode(S4, INPUT_PULLUP);
  38.  
  39. pinMode(S5, INPUT_PULLUP);
  40.  
  41. pinMode(L1, OUTPUT); // if using leds please remember to use series resistors with them
  42.  
  43. pinMode(L2, OUTPUT);
  44.  
  45. pinMode(L3, OUTPUT);
  46.  
  47. pinMode(L4, OUTPUT);
  48.  
  49. pinMode(L5, OUTPUT);
  50.  
  51. pinMode(B, OUTPUT); // buzzer wired from output pin to ground
  52.  
  53. }
  54.  
  55. void loop() {
  56.  
  57. if (!digitalRead(S1))
  58.  
  59. { digitalWrite(L1,HIGH); // turn on lamp 1
  60.  
  61. digitalWrite(B,HIGH); // turn on buzzer
  62.  
  63. delay(500); // wait 2 seconds
  64.  
  65. digitalWrite(B,LOW); // turn off buffer
  66.  
  67. delay(5000); // wait 28 more seconds
  68.  
  69. digitalWrite(L1,LOW); // turn off lamp 1
  70.  
  71. }
  72.  
  73. if (!digitalRead(S2))
  74.  
  75. { digitalWrite(L2,HIGH); // turn on lamp 2
  76.  
  77. digitalWrite(B,HIGH); // turn on buzzer
  78.  
  79. delay(300); // wait 2 seconds
  80.  
  81. digitalWrite(B,LOW); // turn off buzzer
  82.  
  83. delay(300);
  84.  
  85. digitalWrite(B,HIGH); // turn on buzzer
  86.  
  87. delay(300); // wait 2 seconds
  88.  
  89. digitalWrite(B,LOW); // turn off buzzer
  90.  
  91. delay(5000); // wait 26 more seconds
  92.  
  93. digitalWrite(L2,LOW); // turn off lamp 2
  94.  
  95. }
  96.  
  97. if (!digitalRead(S3))
  98.  
  99. { digitalWrite(L3,HIGH); // turn on lamp 3
  100.  
  101. digitalWrite(B,HIGH); // turn on buzzer
  102.  
  103. delay(300); // wait 2 seconds
  104.  
  105. digitalWrite(B,LOW); // turn off buffer
  106.  
  107. delay(300);
  108.  
  109. digitalWrite(B,HIGH); // turn on buzzer
  110.  
  111. delay(300); // wait 2 seconds
  112.  
  113. digitalWrite(B,LOW); // turn off buffer
  114.  
  115. delay(300);
  116.  
  117. digitalWrite(B,HIGH); // turn on buzzer
  118.  
  119. delay(300); // wait 2 seconds
  120.  
  121. digitalWrite(B,LOW); // turn off buffer
  122.  
  123. delay(4800); // wait 28 more seconds
  124.  
  125. digitalWrite(L3,LOW); // turn off lamp 3
  126.  
  127. }
  128.  
  129. if (!digitalRead(S4))
  130.  
  131. { digitalWrite(L4,HIGH); // turn on lamp 4
  132.  
  133. digitalWrite(B,HIGH); // turn on buzzer
  134.  
  135. delay(300); // wait 2 seconds
  136.  
  137. digitalWrite(B,LOW); // turn off buffer
  138.  
  139. delay(300);
  140.  
  141. digitalWrite(B,HIGH); // turn on buzzer
  142.  
  143. delay(300); // wait 2 seconds
  144.  
  145. digitalWrite(B,LOW); // turn off buffer
  146.  
  147. delay(300);
  148.  
  149. digitalWrite(B,HIGH); // turn on buzzer
  150.  
  151. delay(300); // wait 2 seconds
  152.  
  153. digitalWrite(B,LOW); // turn off buffer
  154.  
  155. delay(300);
  156.  
  157. digitalWrite(B,HIGH); // turn on buzzer
  158.  
  159. delay(300); // wait 2 seconds
  160.  
  161. digitalWrite(B,LOW); // turn off buffer
  162.  
  163. delay(4800); // wait 28 more seconds
  164.  
  165. digitalWrite(L4,LOW); // turn off lamp 4
  166.  
  167. }
  168.  
  169. if (!digitalRead(S5))
  170.  
  171. { digitalWrite(L5,HIGH); // turn on lamp 5
  172.  
  173. digitalWrite(B,HIGH); // turn on buzzer
  174.  
  175. delay(500); // wait 2 seconds
  176.  
  177. digitalWrite(B,LOW); // turn off buffer
  178.  
  179. delay(5000); // wait 28 more seconds
  180.  
  181. digitalWrite(L5,LOW); // turn off lamp 5
  182.  
  183. }
  184.  
  185. }
Advertisement
RAW Paste Data Copied
Advertisement