Components and supplies
Resistor 221 ohm
Jumper wires (generic)
Arduino UNO
Buzzer
LED (generic)
Resistor 330 ohm
Tactile Switch, Top Actuated
Project description
Code
untitled
arduino
1const int light11 = 2, light12 = 3, light21 = 4, light22 = 5, light31 = 6, light32 = 7, light41 = 8, light42 = 9, lightStart = 10, buzzer = 11; 2const int button1 = A0, button2 = A1, button3 = A2, button4 = A3; 3const int startTone = 1760, tone1 = 262, tone2 = 330, tone3 = 392, tone4 = 523; 4int score = 0; 5int sDTime = 100; 6int lDTime = 400; 7int rando[8]; 8bool alive = LOW; 9void setup() { 10 pinMode(light11, OUTPUT); 11 pinMode(light12, OUTPUT); 12 pinMode(light21, OUTPUT); 13 pinMode(light22, OUTPUT); 14 pinMode(light31, OUTPUT); 15 pinMode(light32, OUTPUT); 16 pinMode(light41, OUTPUT); 17 pinMode(light42, OUTPUT); 18 pinMode(lightStart, OUTPUT); 19 pinMode(buzzer, OUTPUT); 20 pinMode(button1, INPUT); 21 pinMode(button2, INPUT); 22 pinMode(button3, INPUT); 23 pinMode(button4, INPUT); 24 Serial.begin(9600); 25 pinMode(A4, INPUT); 26 randomSeed(analogRead(A4)); 27} 28 29void loop() { 30 while (alive == HIGH){ 31 rando[0] = random(4); 32 rando[1] = random(4); 33 rando[2] = random(4); 34 rando[3] = random(4); 35 rando[4] = random(4); 36 rando[5] = random(4); 37 rando[6] = random(4); 38 rando[7] = random(4); 39 if (score < 4){ 40 pattern(2); 41 readpattern(2); 42 } 43 else if (score < 8){ 44 pattern(4); 45 readpattern(4); 46 } 47 else if (score < 12){ 48 pattern(8); 49 readpattern(8); 50 } 51 } 52 if (alive == LOW){ 53 digitalWrite(lightStart, HIGH); 54 Serial.println("PRESS ANY BUTTON TO START!"); 55 while(not(digitalRead(button1) == HIGH or digitalRead(button2) == HIGH or digitalRead(button3) == HIGH or digitalRead(button4) == HIGH)){} 56 digitalWrite(lightStart, HIGH); 57 tone(buzzer, startTone); 58 delay(sDTime); 59 digitalWrite(lightStart, LOW); 60 noTone(buzzer); 61 delay(lDTime); 62 alive = HIGH; 63 score = 0; 64 } 65} 66 67void pattern(int num){ 68 for(int ctr = 0; ctr < num; ctr++){ 69 if(rando[ctr] == 0){ 70 digitalWrite(light12, HIGH); 71 tone(buzzer, tone1); 72 delay(sDTime); 73 digitalWrite(light12, LOW); 74 noTone(buzzer); 75 delay(lDTime); 76 } 77 if(rando[ctr] == 1){ 78 digitalWrite(light22, HIGH); 79 tone(buzzer, tone2); 80 delay(sDTime); 81 digitalWrite(light22, LOW); 82 noTone(buzzer); 83 delay(lDTime); 84 } 85 if(rando[ctr] == 2){ 86 digitalWrite(light32, HIGH); 87 tone(buzzer, tone3); 88 delay(sDTime); 89 digitalWrite(light32, LOW); 90 noTone(buzzer); 91 delay(lDTime); 92 } 93 if(rando[ctr] == 3){ 94 digitalWrite(light42, HIGH); 95 tone(buzzer, tone4); 96 delay(sDTime); 97 digitalWrite(light42, LOW); 98 noTone(buzzer); 99 delay(lDTime); 100 } 101 } 102 digitalWrite(lightStart, HIGH); 103 tone(buzzer, startTone); 104 delay(sDTime); 105 digitalWrite(lightStart, LOW); 106 noTone(buzzer); 107} 108 109void readpattern(int num){ 110 for(int ctr = 0; ctr < num; ctr++ && alive == HIGH){ 111 while(not(digitalRead(button1) == HIGH or digitalRead(button2) == HIGH or digitalRead(button3) == HIGH or digitalRead(button4) == HIGH)){} 112 if(digitalRead(button1) == HIGH && rando[ctr] == 0){ 113 digitalWrite(light11, HIGH); 114 tone(buzzer, tone1); 115 delay(sDTime); 116 digitalWrite(light11, LOW); 117 noTone(buzzer); 118 } 119 else if(digitalRead(button2) == HIGH && rando[ctr] == 1){ 120 digitalWrite(light21, HIGH); 121 tone(buzzer, tone2); 122 delay(sDTime); 123 digitalWrite(light21, LOW); 124 noTone(buzzer); 125 } 126 else if(digitalRead(button3) == HIGH && rando[ctr] == 2){ 127 digitalWrite(light31, HIGH); 128 tone(buzzer, tone3); 129 delay(sDTime); 130 digitalWrite(light31, LOW); 131 noTone(buzzer); 132 } 133 else if(digitalRead(button4) == HIGH && rando[ctr] == 3){ 134 digitalWrite(light41, HIGH); 135 tone(buzzer, tone4); 136 delay(sDTime); 137 digitalWrite(light41, LOW); 138 noTone(buzzer); 139 } 140 else{ 141 alive = LOW; 142 } 143 while(digitalRead(button1) == HIGH or digitalRead(button2) == HIGH or digitalRead(button3) == HIGH or digitalRead(button4) == HIGH){} 144 } 145 score++; 146 delay(sDTime); 147 digitalWrite(lightStart, HIGH); 148 tone(buzzer, startTone); 149 delay(sDTime); 150 digitalWrite(lightStart, LOW); 151 noTone(buzzer); 152 delay (lDTime); 153 Serial.println(score); 154}
untitled
arduino
1const int light11 = 2, light12 = 3, light21 = 4, light22 = 5, light31 = 6, light32 = 7, light41 = 8, light42 = 9, lightStart = 10, buzzer = 11; 2const int button1 = A0, button2 = A1, button3 = A2, button4 = A3; 3const int startTone = 1760, tone1 = 262, tone2 = 330, tone3 = 392, tone4 = 523; 4int score = 0; 5int sDTime = 100; 6int lDTime = 400; 7int rando[8]; 8bool alive = LOW; 9void setup() { 10 pinMode(light11, OUTPUT); 11 pinMode(light12, OUTPUT); 12 pinMode(light21, OUTPUT); 13 pinMode(light22, OUTPUT); 14 pinMode(light31, OUTPUT); 15 pinMode(light32, OUTPUT); 16 pinMode(light41, OUTPUT); 17 pinMode(light42, OUTPUT); 18 pinMode(lightStart, OUTPUT); 19 pinMode(buzzer, OUTPUT); 20 pinMode(button1, INPUT); 21 pinMode(button2, INPUT); 22 pinMode(button3, INPUT); 23 pinMode(button4, INPUT); 24 Serial.begin(9600); 25 pinMode(A4, INPUT); 26 randomSeed(analogRead(A4)); 27} 28 29void loop() { 30 while (alive == HIGH){ 31 rando[0] = random(4); 32 rando[1] = random(4); 33 rando[2] = random(4); 34 rando[3] = random(4); 35 rando[4] = random(4); 36 rando[5] = random(4); 37 rando[6] = random(4); 38 rando[7] = random(4); 39 if (score < 4){ 40 pattern(2); 41 readpattern(2); 42 } 43 else if (score < 8){ 44 pattern(4); 45 readpattern(4); 46 } 47 else if (score < 12){ 48 pattern(8); 49 readpattern(8); 50 } 51 } 52 if (alive == LOW){ 53 digitalWrite(lightStart, HIGH); 54 Serial.println("PRESS ANY BUTTON TO START!"); 55 while(not(digitalRead(button1) == HIGH or digitalRead(button2) == HIGH or digitalRead(button3) == HIGH or digitalRead(button4) == HIGH)){} 56 digitalWrite(lightStart, HIGH); 57 tone(buzzer, startTone); 58 delay(sDTime); 59 digitalWrite(lightStart, LOW); 60 noTone(buzzer); 61 delay(lDTime); 62 alive = HIGH; 63 score = 0; 64 } 65} 66 67void pattern(int num){ 68 for(int ctr = 0; ctr < num; ctr++){ 69 if(rando[ctr] == 0){ 70 digitalWrite(light12, HIGH); 71 tone(buzzer, tone1); 72 delay(sDTime); 73 digitalWrite(light12, LOW); 74 noTone(buzzer); 75 delay(lDTime); 76 } 77 if(rando[ctr] == 1){ 78 digitalWrite(light22, HIGH); 79 tone(buzzer, tone2); 80 delay(sDTime); 81 digitalWrite(light22, LOW); 82 noTone(buzzer); 83 delay(lDTime); 84 } 85 if(rando[ctr] == 2){ 86 digitalWrite(light32, HIGH); 87 tone(buzzer, tone3); 88 delay(sDTime); 89 digitalWrite(light32, LOW); 90 noTone(buzzer); 91 delay(lDTime); 92 } 93 if(rando[ctr] == 3){ 94 digitalWrite(light42, HIGH); 95 tone(buzzer, tone4); 96 delay(sDTime); 97 digitalWrite(light42, LOW); 98 noTone(buzzer); 99 delay(lDTime); 100 } 101 } 102 digitalWrite(lightStart, HIGH); 103 tone(buzzer, startTone); 104 delay(sDTime); 105 digitalWrite(lightStart, LOW); 106 noTone(buzzer); 107} 108 109void readpattern(int num){ 110 for(int ctr = 0; ctr < num; ctr++ && alive == HIGH){ 111 while(not(digitalRead(button1) == HIGH or digitalRead(button2) == HIGH or digitalRead(button3) == HIGH or digitalRead(button4) == HIGH)){} 112 if(digitalRead(button1) == HIGH && rando[ctr] == 0){ 113 digitalWrite(light11, HIGH); 114 tone(buzzer, tone1); 115 delay(sDTime); 116 digitalWrite(light11, LOW); 117 noTone(buzzer); 118 } 119 else if(digitalRead(button2) == HIGH && rando[ctr] == 1){ 120 digitalWrite(light21, HIGH); 121 tone(buzzer, tone2); 122 delay(sDTime); 123 digitalWrite(light21, LOW); 124 noTone(buzzer); 125 } 126 else if(digitalRead(button3) == HIGH && rando[ctr] == 2){ 127 digitalWrite(light31, HIGH); 128 tone(buzzer, tone3); 129 delay(sDTime); 130 digitalWrite(light31, LOW); 131 noTone(buzzer); 132 } 133 else if(digitalRead(button4) == HIGH && rando[ctr] == 3){ 134 digitalWrite(light41, HIGH); 135 tone(buzzer, tone4); 136 delay(sDTime); 137 digitalWrite(light41, LOW); 138 noTone(buzzer); 139 } 140 else{ 141 alive = LOW; 142 } 143 while(digitalRead(button1) == HIGH or digitalRead(button2) == HIGH or digitalRead(button3) == HIGH or digitalRead(button4) == HIGH){} 144 } 145 score++; 146 delay(sDTime); 147 digitalWrite(lightStart, HIGH); 148 tone(buzzer, startTone); 149 delay(sDTime); 150 digitalWrite(lightStart, LOW); 151 noTone(buzzer); 152 delay (lDTime); 153 Serial.println(score); 154}
untitled
arduino
1const int light11 = 2, light12 = 3, light21 = 4, light22 = 5, light31 2 = 6, light32 = 7, light41 = 8, light42 = 9, lightStart = 10, buzzer = 11; 3const 4 int button1 = A0, button2 = A1, button3 = A2, button4 = A3; 5const int startTone 6 = 1760, tone1 = 262, tone2 = 330, tone3 = 392, tone4 = 523; 7int score = 0; 8int 9 sDTime = 100; 10int lDTime = 400; 11int rando[8]; 12bool alive = LOW; 13void 14 setup() { 15 pinMode(light11, OUTPUT); 16 pinMode(light12, OUTPUT); 17 pinMode(light21, 18 OUTPUT); 19 pinMode(light22, OUTPUT); 20 pinMode(light31, OUTPUT); 21 pinMode(light32, 22 OUTPUT); 23 pinMode(light41, OUTPUT); 24 pinMode(light42, OUTPUT); 25 pinMode(lightStart, 26 OUTPUT); 27 pinMode(buzzer, OUTPUT); 28 pinMode(button1, INPUT); 29 pinMode(button2, 30 INPUT); 31 pinMode(button3, INPUT); 32 pinMode(button4, INPUT); 33 Serial.begin(9600); 34 35 pinMode(A4, INPUT); 36 randomSeed(analogRead(A4)); 37} 38 39void loop() { 40 41 while (alive == HIGH){ 42 rando[0] = random(4); 43 rando[1] = random(4); 44 45 rando[2] = random(4); 46 rando[3] = random(4); 47 rando[4] = random(4); 48 49 rando[5] = random(4); 50 rando[6] = random(4); 51 rando[7] = random(4); 52 53 if (score < 4){ 54 pattern(2); 55 readpattern(2); 56 } 57 else 58 if (score < 8){ 59 pattern(4); 60 readpattern(4); 61 } 62 else 63 if (score < 12){ 64 pattern(8); 65 readpattern(8); 66 } 67 } 68 69 if (alive == LOW){ 70 digitalWrite(lightStart, HIGH); 71 Serial.println("PRESS 72 ANY BUTTON TO START!"); 73 while(not(digitalRead(button1) == HIGH or digitalRead(button2) 74 == HIGH or digitalRead(button3) == HIGH or digitalRead(button4) == HIGH)){} 75 76 digitalWrite(lightStart, HIGH); 77 tone(buzzer, startTone); 78 delay(sDTime); 79 80 digitalWrite(lightStart, LOW); 81 noTone(buzzer); 82 delay(lDTime); 83 84 alive = HIGH; 85 score = 0; 86 } 87} 88 89void pattern(int num){ 90 91 for(int ctr = 0; ctr < num; ctr++){ 92 if(rando[ctr] == 0){ 93 digitalWrite(light12, 94 HIGH); 95 tone(buzzer, tone1); 96 delay(sDTime); 97 digitalWrite(light12, 98 LOW); 99 noTone(buzzer); 100 delay(lDTime); 101 } 102 if(rando[ctr] 103 == 1){ 104 digitalWrite(light22, HIGH); 105 tone(buzzer, tone2); 106 delay(sDTime); 107 108 digitalWrite(light22, LOW); 109 noTone(buzzer); 110 delay(lDTime); 111 112 } 113 if(rando[ctr] == 2){ 114 digitalWrite(light32, HIGH); 115 tone(buzzer, 116 tone3); 117 delay(sDTime); 118 digitalWrite(light32, LOW); 119 noTone(buzzer); 120 121 delay(lDTime); 122 } 123 if(rando[ctr] == 3){ 124 digitalWrite(light42, 125 HIGH); 126 tone(buzzer, tone4); 127 delay(sDTime); 128 digitalWrite(light42, 129 LOW); 130 noTone(buzzer); 131 delay(lDTime); 132 } 133 } 134 digitalWrite(lightStart, 135 HIGH); 136 tone(buzzer, startTone); 137 delay(sDTime); 138 digitalWrite(lightStart, 139 LOW); 140 noTone(buzzer); 141} 142 143void readpattern(int num){ 144 for(int ctr 145 = 0; ctr < num; ctr++ && alive == HIGH){ 146 while(not(digitalRead(button1) == 147 HIGH or digitalRead(button2) == HIGH or digitalRead(button3) == HIGH or digitalRead(button4) 148 == HIGH)){} 149 if(digitalRead(button1) == HIGH && rando[ctr] == 0){ 150 digitalWrite(light11, 151 HIGH); 152 tone(buzzer, tone1); 153 delay(sDTime); 154 digitalWrite(light11, 155 LOW); 156 noTone(buzzer); 157 } 158 else if(digitalRead(button2) == HIGH 159 && rando[ctr] == 1){ 160 digitalWrite(light21, HIGH); 161 tone(buzzer, 162 tone2); 163 delay(sDTime); 164 digitalWrite(light21, LOW); 165 noTone(buzzer); 166 167 } 168 else if(digitalRead(button3) == HIGH && rando[ctr] == 2){ 169 digitalWrite(light31, 170 HIGH); 171 tone(buzzer, tone3); 172 delay(sDTime); 173 digitalWrite(light31, 174 LOW); 175 noTone(buzzer); 176 } 177 else if(digitalRead(button4) == HIGH 178 && rando[ctr] == 3){ 179 digitalWrite(light41, HIGH); 180 tone(buzzer, 181 tone4); 182 delay(sDTime); 183 digitalWrite(light41, LOW); 184 noTone(buzzer); 185 186 } 187 else{ 188 alive = LOW; 189 } 190 while(digitalRead(button1) 191 == HIGH or digitalRead(button2) == HIGH or digitalRead(button3) == HIGH or digitalRead(button4) 192 == HIGH){} 193 } 194 score++; 195 delay(sDTime); 196 digitalWrite(lightStart, 197 HIGH); 198 tone(buzzer, startTone); 199 delay(sDTime); 200 digitalWrite(lightStart, 201 LOW); 202 noTone(buzzer); 203 delay (lDTime); 204 Serial.println(score); 205}
Downloadable files
file_000_(2)_KYVwCSRMkX.jpeg
file_000_(2)_KYVwCSRMkX.jpeg
Comments
Only logged in users can leave comments