Components and supplies
Arduino UNO
Pushbutton switch 12mm
Jumper wires (generic)
Rotary potentiometer (generic)
Standard LCD 20x4 White On Blue
USB-A to B Cable
Resistor 221 ohm
Breadboard (generic)
5660mAh Power Bank
Tools and machines
CardBoard Box
Scissors
Scotch
Apps and platforms
Arduino IDE
Project description
Code
Spikes Code
arduino
An example of programmed game for the gamebox.
1/* ____ ____ _____ _____ 2 / _/ / _/ / ___/ / ___/ 3 / / / / \\__ \ \\__ \ 4 _/ / _ _/ / _ ___/ / ___/ / 5/___/(_)___/(_)____(_)____(_) 6 7 ______ ______ _ 8 / ____/ / ____/__ ______________ ______(_)____ 9 / / __ / /_ / _ \\/ ___/ ___/ __ `/ ___/ / ___/ 10/ /_/ /_ / __/ / __/ / / / / /_/ / / / (__ ) 11\\____/(_)_/ \\___/_/ /_/ \\__,_/_/ /_/____/ 12 ______ __ 13 / ____/_______ ____ _/ /_____ ______ 14 / / / ___/ _ \\/ __ `/ __/ __ \\/ ___(_) 15/ /___/ / / __/ /_/ / /_/ /_/ / / _ 16\\____/_/ \\___/\\__,_/\\__/\\____/_/ (_) 17 18 ____ _____ ____ _________ __ __ 19 / __ \\__ // __ \\/ _/ ___// / / / 20 / /_/ //_ </ /_/ // / \\__ \\/ /_/ / 21 / ____/__/ / _, _// / ___/ / __ / 22/_/ /____/_/ |_/___//____/_/ /_/ 23 24 _____ ____ _ 25 |__ // __ )(_) 26 /_ </ __ / / 27 ___/ / /_/ / / 28/____/_____/_/ 29 30 */ 31/* 32 _________ .__ __ 33 / _____/_____ |__| | __ ____ ______ 34 \\_____ \\\\____ \\| | |/ // __ \/ ___/ 35 / \ |_> > | <\ ___/ \\___ \ 36/_______ / __/|__|__|_ \\\\___ >____ > 37 \\/|__| \\/ \\/ \\/ 38 */ 39#include <LiquidCrystal.h> 40LiquidCrystal board(12, 11, 5, 4, 3, 2); 41const int buttonUp = 7; 42const int buttonDown = 9; 43int upState = 0; 44int downState = 0; 45int spyRight = 1; 46int spyLeft = 0; 47int control; 48int fly = 0; 49int randomSpikes; 50int r; 51int l; 52int score = 0; 53int dead0,dead1,dead2; 54bool dead = false; 55byte creeperR [8] = { 56 B01000, 57 B11110, 58 B11011, 59 B11110, 60 B11111, 61 B00100, 62 B00100, 63 B11011, 64}; 65byte creeperL [8] = { 66 B00010, 67 B01111, 68 B11011, 69 B01111, 70 B11111, 71 B00100, 72 B00100, 73 B11011, 74}; 75byte spikeR [8] = { 76 B00001, 77 B00011, 78 B00111, 79 B01111, 80 B11111, 81 B00111, 82 B00011, 83 B00001, 84}; 85byte spikeL [8] = { 86 B10000, 87 B11000, 88 B11100, 89 B11110, 90 B11111, 91 B11100, 92 B11000, 93 B10000, 94}; 95void setup (){ 96 Serial.begin (9600); 97 board.begin (20,4); 98 board.createChar (0,creeperR); 99 board.createChar (3,creeperL); 100 board.createChar (1,spikeR); 101 board.createChar (2,spikeL); 102 board.setCursor (0,0); 103 pinMode (buttonUp,INPUT); 104 pinMode (buttonDown,INPUT); 105} 106void loop (){ 107 if (spyRight == 1){ 108 for (int ran=0;ran<=2;ran++){ 109 randomSpikes = random(0,3); 110 board.setCursor (19,randomSpikes); 111 board.write (byte(1)); 112 switch (ran){ 113 case 0: 114 dead0 = randomSpikes; 115 continue; 116 case 1: 117 dead1 = randomSpikes; 118 continue; 119 case 2: 120 dead2 = randomSpikes; 121 continue; 122 } 123 } 124 flyRight (); 125 board.clear (); 126 score++; 127 } 128 if (spyLeft == 1) { 129 for (int ran=0;ran<=2;ran++){ 130 randomSpikes = random(0,3); 131 board.setCursor (0,randomSpikes); 132 board.write (byte(2)); 133 switch (ran){ 134 case 0: 135 dead0 = randomSpikes; 136 continue; 137 case 1: 138 dead1 = randomSpikes; 139 continue; 140 case 2: 141 dead2 = randomSpikes; 142 continue; 143 } 144 } 145 flyLeft (); 146 board.clear (); 147 score++; 148 } 149} 150int stateControl (){ 151 upState = digitalRead(buttonUp); 152 downState = digitalRead(buttonDown); 153 if (upState == HIGH){ 154 return 1; 155 } 156 if (downState == HIGH){ 157 return 2; 158 } 159 else 160 return 0; 161} 162void flyRight (){ 163 for (r=0;r<20;r++){ 164 if (r==19){ 165 if (fly==dead0){ 166 Serial.print ("GAME OVER"); 167 deadScreen (); 168 break; 169 } 170 if (fly==dead1){ 171 Serial.print ("GAME OVER"); 172 deadScreen (); 173 break; 174 } 175 if (fly==dead2){ 176 Serial.print ("GAME OVER"); 177 deadScreen (); 178 break; 179 } 180 } 181 board.setCursor (r-1,fly); 182 board.print (" "); 183 control = stateControl (); 184 if (control == 1){ 185 if (fly == 0){ 186 fly = 1; 187 } 188 fly --; 189 } 190 if (control == 2){ 191 if (fly == 3){ 192 fly = 2; 193 } 194 fly ++; 195 } 196 board.setCursor (r,fly); 197 board.write (byte(0)); 198 delay (150); 199 if (r>=19){ 200 spyRight = 0; 201 spyLeft = 1; 202 } 203 } 204} 205void flyLeft (){ 206 for (l=19;l>=0;l--){ 207 if (l==0){ 208 if (fly==dead0){ 209 Serial.print ("GAME OVER"); 210 deadScreen (); 211 break; 212 } 213 if (fly==dead1){ 214 Serial.print ("GAME OVER"); 215 deadScreen (); 216 break; 217 } 218 if (fly==dead2){ 219 Serial.print ("GAME OVER"); 220 deadScreen (); 221 break; 222 } 223 } 224 board.setCursor ((l+1),fly); 225 board.print (" "); 226 control = stateControl (); 227 if (control == 1){ 228 if (fly == 0){ 229 fly = 1; 230 } 231 fly --; 232 } 233 if (control == 2){ 234 if (fly == 3){ 235 fly = 2; 236 } 237 fly ++; 238 } 239 board.setCursor (l,fly); 240 board.write (byte(3)); 241 delay (150); 242 if (l==0){ 243 spyRight = 1; 244 spyLeft = 0; 245 } 246 } 247} 248void deadScreen (void){ 249 while (control == 0){ 250 board.clear (); 251 board.setCursor (5,1); 252 board.print ("GAME OVER!"); 253 board.setCursor (5,2); 254 board.print ("Punteggio:"); 255 board.print (score); 256 board.setCursor (0,0); 257 board.print ("Premere un tasto"); 258 board.setCursor (0,3); 259 board.print ("per riprovare!"); 260 control = stateControl (); 261 delay (100); 262 } 263 spyRight = 1; 264 spyLeft = 0; 265 score = 0; 266 dead0,dead1,dead2 = 0; 267 dead = true; 268} 269 270
Spikes Code
arduino
An example of programmed game for the gamebox.
1/* ____ ____ _____ _____ 2 / _/ / _/ / ___/ / ___/ 3 4 / / / / \\__ \ \\__ \ 5 _/ / _ _/ / _ ___/ / ___/ / 6/___/(_)___/(_)____(_)____(_) 7 8 9 ______ ______ _ 10 11 / ____/ / ____/__ ______________ ______(_)____ 12 / / __ / /_ / _ \\/ ___/ 13 ___/ __ `/ ___/ / ___/ 14/ /_/ /_ / __/ / __/ / / / / /_/ / / / (__ ) 15\\____/(_)_/ 16 \\___/_/ /_/ \\__,_/_/ /_/____/ 17 ______ __ 18 19 / ____/_______ ____ _/ /_____ ______ 20 / / / ___/ _ \\/ __ `/ __/ __ \\/ 21 ___(_) 22/ /___/ / / __/ /_/ / /_/ /_/ / / _ 23\\____/_/ \\___/\\__,_/\\__/\\____/_/ 24 (_) 25 26 ____ _____ ____ _________ __ __ 27 / __ \\__ // __ \\/ 28 _/ ___// / / / 29 / /_/ //_ </ /_/ // / \\__ \\/ /_/ / 30 / ____/__/ / _, 31 _// / ___/ / __ / 32/_/ /____/_/ |_/___//____/_/ /_/ 33 34 _____ ____ 35 _ 36 |__ // __ )(_) 37 /_ </ __ / / 38 ___/ / /_/ / / 39/____/_____/_/ 40 41 42 */ 43/* 44 45 _________ .__ __ 46 / _____/_____ |__| | __ ____ ______ 47 48 \\_____ \\\\____ \\| | |/ // __ \/ ___/ 49 / \ |_> > | <\ ___/ 50 \\___ \ 51/_______ / __/|__|__|_ \\\\___ >____ > 52 \\/|__| \\/ 53 \\/ \\/ 54 */ 55#include <LiquidCrystal.h> 56LiquidCrystal board(12, 57 11, 5, 4, 3, 2); 58const int buttonUp = 7; 59const int buttonDown = 9; 60int 61 upState = 0; 62int downState = 0; 63int spyRight = 1; 64int spyLeft = 0; 65int 66 control; 67int fly = 0; 68int randomSpikes; 69int r; 70int l; 71int score = 72 0; 73int dead0,dead1,dead2; 74bool dead = false; 75byte creeperR [8] = { 76 77 B01000, 78 B11110, 79 B11011, 80 B11110, 81 B11111, 82 B00100, 83 B00100, 84 85 B11011, 86}; 87byte creeperL [8] = { 88 B00010, 89 B01111, 90 B11011, 91 92 B01111, 93 B11111, 94 B00100, 95 B00100, 96 B11011, 97}; 98byte spikeR 99 [8] = { 100 B00001, 101 B00011, 102 B00111, 103 B01111, 104 B11111, 105 B00111, 106 107 B00011, 108 B00001, 109}; 110byte spikeL [8] = { 111 B10000, 112 B11000, 113 114 B11100, 115 B11110, 116 B11111, 117 B11100, 118 B11000, 119 B10000, 120}; 121void 122 setup (){ 123 Serial.begin (9600); 124 board.begin (20,4); 125 board.createChar 126 (0,creeperR); 127 board.createChar (3,creeperL); 128 board.createChar (1,spikeR); 129 130 board.createChar (2,spikeL); 131 board.setCursor (0,0); 132 pinMode (buttonUp,INPUT); 133 134 pinMode (buttonDown,INPUT); 135} 136void loop (){ 137 if (spyRight == 1){ 138 139 for (int ran=0;ran<=2;ran++){ 140 randomSpikes = random(0,3); 141 board.setCursor 142 (19,randomSpikes); 143 board.write (byte(1)); 144 switch (ran){ 145 case 146 0: 147 dead0 = randomSpikes; 148 continue; 149 case 1: 150 dead1 151 = randomSpikes; 152 continue; 153 case 2: 154 dead2 = randomSpikes; 155 156 continue; 157 } 158 } 159 flyRight (); 160 board.clear (); 161 score++; 162 163 } 164 if (spyLeft == 1) { 165 for (int ran=0;ran<=2;ran++){ 166 randomSpikes 167 = random(0,3); 168 board.setCursor (0,randomSpikes); 169 board.write (byte(2)); 170 171 switch (ran){ 172 case 0: 173 dead0 = randomSpikes; 174 continue; 175 176 case 1: 177 dead1 = randomSpikes; 178 continue; 179 case 2: 180 181 dead2 = randomSpikes; 182 continue; 183 } 184 } 185 flyLeft (); 186 187 board.clear (); 188 score++; 189 } 190} 191int stateControl (){ 192 upState 193 = digitalRead(buttonUp); 194 downState = digitalRead(buttonDown); 195 if (upState 196 == HIGH){ 197 return 1; 198 } 199 if (downState == HIGH){ 200 return 2; 201 202 } 203 else 204 return 0; 205} 206void flyRight (){ 207 for (r=0;r<20;r++){ 208 209 if (r==19){ 210 if (fly==dead0){ 211 Serial.print ("GAME OVER"); 212 213 deadScreen (); 214 break; 215 } 216 if (fly==dead1){ 217 218 Serial.print ("GAME OVER"); 219 deadScreen (); 220 break; 221 222 } 223 if (fly==dead2){ 224 Serial.print ("GAME OVER"); 225 deadScreen 226 (); 227 break; 228 } 229 } 230 board.setCursor (r-1,fly); 231 232 board.print (" "); 233 control = stateControl (); 234 if (control == 235 1){ 236 if (fly == 0){ 237 fly = 1; 238 } 239 fly --; 240 241 } 242 if (control == 2){ 243 if (fly == 3){ 244 fly = 2; 245 246 } 247 fly ++; 248 } 249 board.setCursor (r,fly); 250 board.write 251 (byte(0)); 252 delay (150); 253 if (r>=19){ 254 spyRight = 0; 255 spyLeft 256 = 1; 257 } 258 } 259} 260void flyLeft (){ 261 for (l=19;l>=0;l--){ 262 if 263 (l==0){ 264 if (fly==dead0){ 265 Serial.print ("GAME OVER"); 266 deadScreen 267 (); 268 break; 269 } 270 if (fly==dead1){ 271 Serial.print 272 ("GAME OVER"); 273 deadScreen (); 274 break; 275 } 276 if 277 (fly==dead2){ 278 Serial.print ("GAME OVER"); 279 deadScreen (); 280 281 break; 282 } 283 } 284 board.setCursor ((l+1),fly); 285 board.print 286 (" "); 287 control = stateControl (); 288 if (control == 1){ 289 if 290 (fly == 0){ 291 fly = 1; 292 } 293 fly --; 294 } 295 if (control 296 == 2){ 297 if (fly == 3){ 298 fly = 2; 299 } 300 fly ++; 301 302 } 303 board.setCursor (l,fly); 304 board.write (byte(3)); 305 delay 306 (150); 307 if (l==0){ 308 spyRight = 1; 309 spyLeft = 0; 310 } 311 312 } 313} 314void deadScreen (void){ 315 while (control == 0){ 316 board.clear 317 (); 318 board.setCursor (5,1); 319 board.print ("GAME OVER!"); 320 board.setCursor 321 (5,2); 322 board.print ("Punteggio:"); 323 board.print (score); 324 board.setCursor 325 (0,0); 326 board.print ("Premere un tasto"); 327 board.setCursor (0,3); 328 329 board.print ("per riprovare!"); 330 control = stateControl (); 331 delay 332 (100); 333 } 334 spyRight = 1; 335 spyLeft = 0; 336 score = 0; 337 dead0,dead1,dead2 338 = 0; 339 dead = true; 340} 341 342
Downloadable files
GameBox_Schematics
The schematic of the console, is used to build it.
GameBox_Schematics
GameBox_Schematics
The schematic of the console, is used to build it.
GameBox_Schematics
GameBox_Schematics Image
GameBox_Schematics Image
Comments
Only logged in users can leave comments