Components and supplies
Custom PCB
Resistor 10k ohm
Pushbutton switch 12mm
Male-Header 36 Position 1 Row- Long (0.1")
3 mm LED: Red
Resistor 220 ohm
Arduino UNO
5 mm LED: Green
Tools and machines
Soldering iron (generic)
Apps and platforms
Arduino IDE
Project description
Code
Arduino code
arduino
the code to run the game
1//set pins 2int button0pin = 2; 3int selectedpin = 11; //selected light from pin 3 to 11 4int button10pin = 12; 5int resetpin = 13; 6 7 8//set variables 9int clockspeed = 50; //miliseconds 10int menutickspeed = 1000; //how long between next LED light up 11int holdexitmenu = 5000; //time for holding both buttons to exit main menu mode 12int holdrestart = 5000; 13int button0holdtime = 0; //how long button has been held in miliseconds 14int button10holdtime = 0; 15 16boolean backwards = false; 17boolean button0press = false; 18boolean button10press = false; 19 20int stoppin; //pin player(s) stop at 21int smallplayerscore = 0; 22int bigplayerscore = 0; 23int notchanging = 1; 24int i; 25int j; 26 27 28 29void(* resetFunc) (void) = 0; //declare reset function @ address 0 30 31 32 33 34 35void setup() { 36//set pinmodes 37pinMode(button0pin, INPUT); 38for (i=3; i<=11; i=i+1) { 39 pinMode(i, OUTPUT); 40} 41pinMode(button10pin, INPUT); 42pinMode(resetpin, INPUT); 43 44 45//be in main menu state until both buttons pressed 46while (button0holdtime < holdexitmenu && button10holdtime < holdexitmenu) { 47 delay(menutickspeed); //delay each "tick" by clock speed 48 49 if (digitalRead(resetpin) == HIGH) { 50 for (i=3; i<=11; i=i+1) { //reset all pins 51 digitalWrite(i, LOW); 52 } 53 resetFunc(); //restart program 54 55 } 56 if (digitalRead(button0pin) == HIGH) { //test if button0 is pressed 57 button0press = true; 58 button0holdtime = button0holdtime + menutickspeed; 59 } 60 else { 61 button0press = false; 62 button0holdtime = 0; 63 } 64 65 66 if (digitalRead(button10pin) == HIGH) { //test if button10 is pressed 67 button10press = true; 68 button10holdtime = button10holdtime + menutickspeed; 69 } 70 else { 71 button10press = false; 72 button10holdtime = 0; 73 } 74 75 76 77 78 79 if (backwards == false) { ////meue lighting program 80 81 if (selectedpin != 11) { 82 digitalWrite(selectedpin, HIGH); 83 digitalWrite((selectedpin - 1), LOW); 84 selectedpin = selectedpin + 1; 85 } 86 87 else { 88 digitalWrite(selectedpin, HIGH); 89 digitalWrite((selectedpin - 1), LOW); 90 selectedpin = selectedpin - 1; 91 backwards = true; 92 } 93 94 } 95 96 else { 97 98 if (selectedpin != 3) { 99 digitalWrite(selectedpin, HIGH); 100 digitalWrite((selectedpin + 1), LOW); 101 selectedpin = selectedpin - 1; 102 } 103 104 else { 105 digitalWrite(selectedpin, HIGH); 106 digitalWrite((selectedpin + 1), LOW); 107 selectedpin = selectedpin + 1; 108 backwards = false; 109 } 110 111 } 112 113} 114 115 116//exit main menu (all lights flash 3 times) 117for(j=1; j<=3; j=j+1) { 118 for (i=3; i<=11; i=i+1) { 119 digitalWrite(i, LOW); 120 } 121 delay(500); 122 for (i=3; i<=11; i=i+1) { 123 digitalWrite(i, HIGH); 124 } 125 delay(500); 126} 127 128 for (i=3; i<=11; i=i+1) { //reset all pins 129 digitalWrite(i, LOW); 130 } 131 132button0holdtime = 0; 133button10holdtime = 0; 134 135} 136 137 138 139 140 141 142 143 144 145 146void loop() { 147 delay(clockspeed); 148 //test if reset 149 if (digitalRead(resetpin) == HIGH) { 150 for (i=3; i<=11; i=i+1) { //reset all pins 151 digitalWrite(i, LOW); 152 } 153 resetFunc(); //restart program 154 } 155 156 157 //read 0 button 158 if (digitalRead(button0pin) == HIGH){ 159 button0press = true; 160 161 if (selectedpin == 11) { //test if big player score 162 bigplayerscore = bigplayerscore + 1; //add score 163 164 if (bigplayerscore >= 5) { //test if win 165 for (i=3; i<=11; i=i+1) { //run win program 166 digitalWrite(i, LOW); 167 } 168 169 while(notchanging == 1) {//make infinite loop unless reset 170 digitalWrite(11, HIGH); 171 delay(500); 172 digitalWrite(11, LOW); 173 delay(500); 174 175 //test if reset 176 if (digitalRead(resetpin) == HIGH) { 177 for (i=3; i<=11; i=i+1) { //reset all pins 178 digitalWrite(i, LOW); 179 } 180 resetFunc(); //restart program 181 } 182 } 183 } 184 185 186 for (i=3; i<=11; i=i+1) { //turn all lights off 187 digitalWrite(i, LOW); 188 } 189 for (i=1; i<=bigplayerscore; i=i+1) { //if score, flash light 190 digitalWrite(11, LOW); 191 delay(500); 192 digitalWrite(11, HIGH); 193 delay(500); 194 } 195 } 196 197 for (i=3; i<=11; i=i+1) { //turn all lights off 198 digitalWrite(i, LOW); 199 } 200 for (i=3; i<=11; i=i+1) { //reset all pins 201 digitalWrite(i, LOW); 202 } 203 digitalWrite(selectedpin, HIGH); 204 delay(500); 205 digitalWrite(selectedpin,LOW); 206 207 } 208 209 else { 210 button0press = false; 211 } 212 213 214 215 216 //read 10 button 217 if (digitalRead(button10pin) == HIGH){ 218 button10press = true; 219 220 if (selectedpin == 3) { //test if small player score 221 smallplayerscore = smallplayerscore + 1; //add score 222 223 if (smallplayerscore >= 5) { //test if win 224 for (i=3; i<=11; i=i+1) { //run win program 225 digitalWrite(i, LOW); 226 } 227 228 while(notchanging == 1) {//make infinite loop unless reset 229 digitalWrite(3, HIGH); 230 delay(500); 231 digitalWrite(3, LOW); 232 delay(500); 233 234 //test if reset 235 if (digitalRead(resetpin) == HIGH) { 236 for (i=3; i<=11; i=i+1) { //reset all pins 237 digitalWrite(i, LOW); 238 } 239 resetFunc(); //restart program 240 } 241 } 242 } 243 244 245 for (i=3; i<=11; i=i+1) { //turn all lights off 246 digitalWrite(i, LOW); 247 } 248 for (i=1; i<=smallplayerscore; i=i+1) { //if score, flash light 249 digitalWrite(3, LOW); 250 delay(500); 251 digitalWrite(3, HIGH); 252 delay(500); 253 } 254 } 255 256 for (i=3; i<=11; i=i+1) { //turn all lights off 257 digitalWrite(i, LOW); 258 } 259 for (i=3; i<=11; i=i+1) { //reset all pins 260 digitalWrite(i, LOW); 261 } 262 digitalWrite(selectedpin, HIGH); 263 delay(500); 264 digitalWrite(selectedpin,LOW); 265 266 } 267 else { 268 button10press = false; 269 } 270 271 272 273 274 275 if (backwards == false) { ////flashing back and forth 276 277 if (selectedpin != 11) { 278 digitalWrite(selectedpin, HIGH); 279 digitalWrite((selectedpin - 1), LOW); 280 selectedpin = selectedpin + 1; 281 } 282 283 else { 284 digitalWrite(selectedpin, HIGH); 285 digitalWrite((selectedpin - 1), LOW); 286 selectedpin = selectedpin - 1; 287 backwards = true; 288 } 289 290 } 291 292 293 294 295 else { 296 297 if (selectedpin != 3) { 298 digitalWrite(selectedpin, HIGH); 299 digitalWrite((selectedpin + 1), LOW); 300 selectedpin = selectedpin - 1; 301 } 302 303 else { 304 digitalWrite(selectedpin, HIGH); 305 digitalWrite((selectedpin + 1), LOW); 306 selectedpin = selectedpin + 1; 307 backwards = false; 308 } 309 310 } 311 312 313} 314 315
Arduino code
arduino
the code to run the game
1//set pins 2int button0pin = 2; 3int selectedpin = 11; //selected light from pin 3 to 11 4int button10pin = 12; 5int resetpin = 13; 6 7 8//set variables 9int clockspeed = 50; //miliseconds 10int menutickspeed = 1000; //how long between next LED light up 11int holdexitmenu = 5000; //time for holding both buttons to exit main menu mode 12int holdrestart = 5000; 13int button0holdtime = 0; //how long button has been held in miliseconds 14int button10holdtime = 0; 15 16boolean backwards = false; 17boolean button0press = false; 18boolean button10press = false; 19 20int stoppin; //pin player(s) stop at 21int smallplayerscore = 0; 22int bigplayerscore = 0; 23int notchanging = 1; 24int i; 25int j; 26 27 28 29void(* resetFunc) (void) = 0; //declare reset function @ address 0 30 31 32 33 34 35void setup() { 36//set pinmodes 37pinMode(button0pin, INPUT); 38for (i=3; i<=11; i=i+1) { 39 pinMode(i, OUTPUT); 40} 41pinMode(button10pin, INPUT); 42pinMode(resetpin, INPUT); 43 44 45//be in main menu state until both buttons pressed 46while (button0holdtime < holdexitmenu && button10holdtime < holdexitmenu) { 47 delay(menutickspeed); //delay each "tick" by clock speed 48 49 if (digitalRead(resetpin) == HIGH) { 50 for (i=3; i<=11; i=i+1) { //reset all pins 51 digitalWrite(i, LOW); 52 } 53 resetFunc(); //restart program 54 55 } 56 if (digitalRead(button0pin) == HIGH) { //test if button0 is pressed 57 button0press = true; 58 button0holdtime = button0holdtime + menutickspeed; 59 } 60 else { 61 button0press = false; 62 button0holdtime = 0; 63 } 64 65 66 if (digitalRead(button10pin) == HIGH) { //test if button10 is pressed 67 button10press = true; 68 button10holdtime = button10holdtime + menutickspeed; 69 } 70 else { 71 button10press = false; 72 button10holdtime = 0; 73 } 74 75 76 77 78 79 if (backwards == false) { ////meue lighting program 80 81 if (selectedpin != 11) { 82 digitalWrite(selectedpin, HIGH); 83 digitalWrite((selectedpin - 1), LOW); 84 selectedpin = selectedpin + 1; 85 } 86 87 else { 88 digitalWrite(selectedpin, HIGH); 89 digitalWrite((selectedpin - 1), LOW); 90 selectedpin = selectedpin - 1; 91 backwards = true; 92 } 93 94 } 95 96 else { 97 98 if (selectedpin != 3) { 99 digitalWrite(selectedpin, HIGH); 100 digitalWrite((selectedpin + 1), LOW); 101 selectedpin = selectedpin - 1; 102 } 103 104 else { 105 digitalWrite(selectedpin, HIGH); 106 digitalWrite((selectedpin + 1), LOW); 107 selectedpin = selectedpin + 1; 108 backwards = false; 109 } 110 111 } 112 113} 114 115 116//exit main menu (all lights flash 3 times) 117for(j=1; j<=3; j=j+1) { 118 for (i=3; i<=11; i=i+1) { 119 digitalWrite(i, LOW); 120 } 121 delay(500); 122 for (i=3; i<=11; i=i+1) { 123 digitalWrite(i, HIGH); 124 } 125 delay(500); 126} 127 128 for (i=3; i<=11; i=i+1) { //reset all pins 129 digitalWrite(i, LOW); 130 } 131 132button0holdtime = 0; 133button10holdtime = 0; 134 135} 136 137 138 139 140 141 142 143 144 145 146void loop() { 147 delay(clockspeed); 148 //test if reset 149 if (digitalRead(resetpin) == HIGH) { 150 for (i=3; i<=11; i=i+1) { //reset all pins 151 digitalWrite(i, LOW); 152 } 153 resetFunc(); //restart program 154 } 155 156 157 //read 0 button 158 if (digitalRead(button0pin) == HIGH){ 159 button0press = true; 160 161 if (selectedpin == 11) { //test if big player score 162 bigplayerscore = bigplayerscore + 1; //add score 163 164 if (bigplayerscore >= 5) { //test if win 165 for (i=3; i<=11; i=i+1) { //run win program 166 digitalWrite(i, LOW); 167 } 168 169 while(notchanging == 1) {//make infinite loop unless reset 170 digitalWrite(11, HIGH); 171 delay(500); 172 digitalWrite(11, LOW); 173 delay(500); 174 175 //test if reset 176 if (digitalRead(resetpin) == HIGH) { 177 for (i=3; i<=11; i=i+1) { //reset all pins 178 digitalWrite(i, LOW); 179 } 180 resetFunc(); //restart program 181 } 182 } 183 } 184 185 186 for (i=3; i<=11; i=i+1) { //turn all lights off 187 digitalWrite(i, LOW); 188 } 189 for (i=1; i<=bigplayerscore; i=i+1) { //if score, flash light 190 digitalWrite(11, LOW); 191 delay(500); 192 digitalWrite(11, HIGH); 193 delay(500); 194 } 195 } 196 197 for (i=3; i<=11; i=i+1) { //turn all lights off 198 digitalWrite(i, LOW); 199 } 200 for (i=3; i<=11; i=i+1) { //reset all pins 201 digitalWrite(i, LOW); 202 } 203 digitalWrite(selectedpin, HIGH); 204 delay(500); 205 digitalWrite(selectedpin,LOW); 206 207 } 208 209 else { 210 button0press = false; 211 } 212 213 214 215 216 //read 10 button 217 if (digitalRead(button10pin) == HIGH){ 218 button10press = true; 219 220 if (selectedpin == 3) { //test if small player score 221 smallplayerscore = smallplayerscore + 1; //add score 222 223 if (smallplayerscore >= 5) { //test if win 224 for (i=3; i<=11; i=i+1) { //run win program 225 digitalWrite(i, LOW); 226 } 227 228 while(notchanging == 1) {//make infinite loop unless reset 229 digitalWrite(3, HIGH); 230 delay(500); 231 digitalWrite(3, LOW); 232 delay(500); 233 234 //test if reset 235 if (digitalRead(resetpin) == HIGH) { 236 for (i=3; i<=11; i=i+1) { //reset all pins 237 digitalWrite(i, LOW); 238 } 239 resetFunc(); //restart program 240 } 241 } 242 } 243 244 245 for (i=3; i<=11; i=i+1) { //turn all lights off 246 digitalWrite(i, LOW); 247 } 248 for (i=1; i<=smallplayerscore; i=i+1) { //if score, flash light 249 digitalWrite(3, LOW); 250 delay(500); 251 digitalWrite(3, HIGH); 252 delay(500); 253 } 254 } 255 256 for (i=3; i<=11; i=i+1) { //turn all lights off 257 digitalWrite(i, LOW); 258 } 259 for (i=3; i<=11; i=i+1) { //reset all pins 260 digitalWrite(i, LOW); 261 } 262 digitalWrite(selectedpin, HIGH); 263 delay(500); 264 digitalWrite(selectedpin,LOW); 265 266 } 267 else { 268 button10press = false; 269 } 270 271 272 273 274 275 if (backwards == false) { ////flashing back and forth 276 277 if (selectedpin != 11) { 278 digitalWrite(selectedpin, HIGH); 279 digitalWrite((selectedpin - 1), LOW); 280 selectedpin = selectedpin + 1; 281 } 282 283 else { 284 digitalWrite(selectedpin, HIGH); 285 digitalWrite((selectedpin - 1), LOW); 286 selectedpin = selectedpin - 1; 287 backwards = true; 288 } 289 290 } 291 292 293 294 295 else { 296 297 if (selectedpin != 3) { 298 digitalWrite(selectedpin, HIGH); 299 digitalWrite((selectedpin + 1), LOW); 300 selectedpin = selectedpin - 1; 301 } 302 303 else { 304 digitalWrite(selectedpin, HIGH); 305 digitalWrite((selectedpin + 1), LOW); 306 selectedpin = selectedpin + 1; 307 backwards = false; 308 } 309 310 } 311 312 313} 314 315
Downloadable files
custom PCB design
This is the PCB Arduino "shield" that will slot onto the Arduino
custom PCB design
Documentation
Gerber file of PCB design
This is the design of the PCB that slots onto the Arduino, it can be sent to any manufacturer for it to be made. It is in Gerber format which is what most manufacturers take.
Gerber file of PCB design
Gerber file of PCB design
This is the design of the PCB that slots onto the Arduino, it can be sent to any manufacturer for it to be made. It is in Gerber format which is what most manufacturers take.
Gerber file of PCB design
Comments
Only logged in users can leave comments
22warehamD
0 Followers
•0 Projects
Table of contents
Intro
6
0