Components and supplies
Panel Mount 1K potentiometer (Breadboard Friendly) - 1K Linear
Machifit V-Slot V Gantry Plat Special Slide Plate Five Roulette for 2040 Aluminum Profile
Gardner Bender GSW-61 Electrical Rotary Switch, SPST
Machifit Aluminum Idler Pulley Plate
5M GT2 Timing Belt With 16T GT2 Timing Pulley
URBEST Inlet Module Plug 5A Fuse Switch Male Power Socket 10A 250V 3 Pin IEC320 C14
Arduino UNO
Acrylic Stand for 16x2 Character LCD
RGB backlight negative LCD 16x2 + extras - RGB on black
Rugged Metal Pushbutton with Blue LED Ring - 16mm Blue Momentary
Nema17 59Ncm 2A 1.8°4-lead 48mm Stepper Motor
MEAN WELL RD-65A Dual Output Enclosed Power Supply 5V 8 Amp and 12V
NeoPixel Ring: WS2812 5050 RGB LED
Adafruit Stereo 20W Class D Audio Amplifier- MAX9744
Adafruit I2C Controlled + Keypad Shield Kit for 16x2 LCD
arcade style buttons
Makerbeam
BIQU Big Aluminum Alloy Gantry Plate+ Plastic Pulley Wheel with Bearing Set for 3D Printer
Arduino MP3 Shield
Acrylic Sheets- 3 mm Thick
EasyDriver - Stepper Motor Driver
Machifit 100-1000mm Black 2040 V-Slot Aluminum Profile Extrusion
Machfit Aluminum Nema 17 Stepper Motor Mount Plate
Acoustic Audio AA321B Mountable Indoor Speakers 400 Watts Black Bookshelf Pair
Tools and machines
Multitool, Screwdriver
jig saw
Drill / Driver, Cordless
Soldering iron (generic)
Project description
Code
Drinking Game For The Brave
arduino
1/*************************************************************** 2* GAME 3* 4 players 4* Drinking Game for the Brave - 08/01/2019 5* This game consists of 4 players waiting for a light to illuminate and once illuminated 6* players attempt to hit their button faster than their opponents. The loser is notified with visual 7* & audio effects as well as a shot glass brought to them on a conveyer belt. 8* This code is a monster mashed hodge podge from multiple original sources & example sketches. 9* I edited what I needed to make this game work. 10* I don't know what I'm doing but I'm learning the hard way! 11* Thank you to Lotte and Arjan for their inspiring 2 person reaction game, and to Adafruit & SparkFun for 12* both being wonderful resources in this amazing journey! 13*****************************************************************/ 14 15#include <Wire.h>//This library allows you to communicate with I2C. 16#include <Adafruit_RGBLCDShield.h> //library for Adafruit RGB LCD Shield 17#include <Adafruit_NeoPixel.h> // library for Neopixels 18#include <SPI.h>//Serial Peripheral Interface (SPI) is an interface bus commonly used to send data 19//between microcontrollers and small peripherals such as shift registers, sensors, and SD cards. 20//It uses separate clock & data lines, along with a select line to choose the device you wish to talk to. 21#include <Adafruit_VS1053.h> //library for Adafruit music maker shield. 22#include <SD.h>//The SD library allows for reading from and writing to SD cards. 23 24#define SHIELD_RESET -1 // VS1053 reset pin (unused!) 25#define SHIELD_CS 7 // VS1053 chip select pin (output) 26#define SHIELD_DCS 6 // VS1053 Data/command select pin (output) 27 28#define CARDCS 4 // Card chip select pin 29// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt 30#define DREQ 3 // VS1053 Data request, ideally an Interrupt pin 31 32Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS); 33 34#define LED_PIN 10 //Neopixel rings 35#define LED_COUNT 24 //24 leds on each ring 36Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); 37 38 39Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield(); 40 41//RGB LCD Shield 42#define RED 0x1 43#define YELLOW 0x3 44#define GREEN 0x2 45#define TEAL 0x6 46#define BLUE 0x4 47#define VIOLET 0x5 48#define WHITE 0x7 49 50//Declare pin functions on Arduino for the SparkFun EasyDriver Stepper Motor Driver 51const int stp = 8; 52const int dir = 9; 53const int en = A2; 54 55 56//Declare variables for functions (Neopixel effects) 57char user_input; 58int x; 59int y; 60int state; 61 62const int switchStart = A0; //Start button 63const int switchPin1 = 0; //Player 1 button (red) 64const int switchPin2 = 5; //Player 2 button (blue) 65const int switchPin3 = 2; //Player 3 button (green) 66const int switchPin4 = A1; //Player 4 button (yellow) 67 68 69 70 71int buttonStateP1 = 0; //Player 1 button tracking 72int buttonStateP2 = 0; //Player 2 button tracking 73int buttonStateP3 = 0; //Player 3 button tracking 74int buttonStateP4 = 0; //Player 4 button tracking 75int lastButtonStateP1 = 0; // Player 1 last button state (used to detect a button press) 76int lastButtonStateP2 = 0; // Player 2 last button state (used to detect a button press) 77int lastButtonStateP3 = 0; // Player 3 last button state (used to detect a button press) 78int lastButtonStateP4 = 0; // Player 4 last button state (used to detect a button press) 79int scoreP1 = 0; // Player 1 score tracking 80int scoreP2 = 0; // Player 2 score tracking 81int scoreP3 = 0; // Player 3 score tracking 82int scoreP4 = 0; // Player 4 score tracking 83boolean allDone = false; // Used to see if all players have pressed their buttons 84boolean gameOn = false; // Keep track if the game is going on or not 85boolean startButtonState = HIGH; // Start button initalization 86 87boolean p1Done = false; // Keep track of Player 1's button press 88boolean p2Done = false; // Keep track of Player 2's button press 89boolean p3Done = false; // Keep track of Player 3's button press 90boolean p4Done = false; // Keep track of Player 4's button press 91 92long randomTime; // Hold the random time between the start of the game and the indicator light coming back on 93long startTime; // When did the game start 94long endTimeP1; // When did Player 1 press their button 95long endTimeP2; // When did Player 2 press their button 96long endTimeP3; // When did Player 3 press their button 97long endTimeP4; // When did Player 4 press their button 98 99float finalTimeP1; // Time elapsed between start of the game and Player 1 pressing their button 100float finalTimeP2; // Time elapsed between start of the game and Player 2 pressing their button 101float finalTimeP3; // Time elapsed between start of the game and Player 3 pressing their button 102float finalTimeP4; // Time elapsed between start of the game and Player 4 pressing their button 103 104void setup() { 105 106 strip.begin();// INITIALIZE NeoPixel strip object (REQUIRED) 107 strip.show(); // Turn OFF all pixels ASAP 108 strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255) 109 theaterChaseRainbow(50); // Rainbow-enhanced theaterChase variant 110 strip.clear(); 111 strip.show(); 112 113 Serial.begin(9600); 114 Serial.println("Adafruit VS1053 Library Test"); 115 116 // initialize the music player 117 if (! musicPlayer.begin()) { // initialise the music player 118 Serial.println(F("Couldn't find VS1053, do you have the right pins defined?")); 119 while (1); 120 } 121 Serial.println(F("VS1053 found")); 122 123 //musicPlayer.sineTest(0x44, 500); // Make a tone to indicate VS1053 is working 124 125 126 if (!SD.begin(CARDCS)) { 127 Serial.println(F("SD failed, or not present")); 128 while (1); // don't do anything more 129 } 130 Serial.println("SD OK!"); 131 132 printDirectory(SD.open("/"), 0); 133 134 // Set volume for left, right channels. lower numbers == louder volume! 135 musicPlayer.setVolume(20,20); 136 137 138 // This option uses a pin interrupt. No timers required! But DREQ 139 // must be on an interrupt pin. For Uno/Duemilanove/Diecimilla 140 // that's Digital #2 or #3 141 // See http://arduino.cc/en/Reference/attachInterrupt for other pins 142 // *** This method is preferred 143 if (! musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT)) 144 Serial.println(F("DREQ pin is not an interrupt pin")); 145 146 147 pinMode(stp, OUTPUT); 148 pinMode(dir, OUTPUT); 149 pinMode(en, OUTPUT); 150 pinMode(switchStart, INPUT_PULLUP); 151 pinMode(switchPin1, INPUT_PULLUP); 152 pinMode(switchPin2, INPUT_PULLUP); 153 pinMode(switchPin3, INPUT_PULLUP); 154 pinMode(switchPin4, INPUT_PULLUP); 155 156 digitalWrite(en,HIGH);//disables stepper 157 158 lcd.begin(16, 2); //lcd size 2 lines, 16 characters 159 lcd.clear(); //clears previous data in display 160 lcd.print(" DRINKING GAME"); 161 lcd.setCursor(0,1); //set invisible cursor to the first column (column 0), second line (line 1) 162 lcd.print(" FOR THE BRAVE"); 163 lcd.setBacklight(WHITE); 164 165 musicPlayer.playFullFile("heathens.mp3");//Intro audio 166} 167 168void loop(){ 169 170 startButtonState = digitalRead(switchStart); // Listen for the start button to be pressed 171 buttonStateP1 = digitalRead(switchPin1); 172 buttonStateP2 = digitalRead(switchPin2); 173 buttonStateP3 = digitalRead(switchPin3); 174 buttonStateP4 = digitalRead(switchPin4); 175 176 // if the start button has been pressed and there is no game already running, begin the game 177 if (startButtonState == LOW && gameOn == false){ 178 Random(); 179 } 180 181 //secret function to play Led Zeppelin album. 182 if (buttonStateP1 == LOW && buttonStateP4 == LOW && gameOn == false) { 183 musicPlayer.playFullFile("zeppelin.mp3"); 184 } 185 186 //led effect when button pressed while game is not going. 187 else if (buttonStateP1 == LOW && gameOn == false) { 188 colorWipe(strip.Color(255, 0, 0), 10); // Red 189 colorWipe(strip.Color( 0, 0, 0), 10); // off 190 strip.show(); 191 } 192 193 //led effect when button pressed while game is not going. 194 else if (buttonStateP2 == LOW && gameOn == false) { 195 colorWipe(strip.Color(0,0,255), 10); // blue 196 colorWipe(strip.Color( 0, 0, 0), 10); // off 197 strip.show(); 198 } 199 200 //led effect when button pressed while game is not going. 201 else if (buttonStateP3 == LOW && gameOn == false) { 202 colorWipe(strip.Color(0,128,0), 10); // green 203 colorWipe(strip.Color( 0, 0, 0), 10); // off 204 strip.show(); 205 } 206 207 //led effect when button pressed while game is not going. 208 else if (buttonStateP4 == LOW && gameOn == false) { 209 colorWipe(strip.Color(255,255,0), 10); // yellow 210 colorWipe(strip.Color( 0, 0, 0), 10); // off 211 strip.show(); 212 } 213} 214 215 216// Generate a random amount of time to delay between the beginning of the game until the LED comes back on 217void Random(){ 218 219 if (! musicPlayer.startPlayingFile("/intense1.mp3")) { 220 // Serial.println("Could not open file intense1.mp3"); 221 while (1); 222 } 223 224 while (musicPlayer.playingMusic) { 225 226 randomTime = random(4,10); 227 randomTime = randomTime*1000; 228 229 //Neopixel effects while waiting to press button 230 colorWipe(strip.Color(255, 0, 0), 15); // Red 231 colorWipe(strip.Color( 0, 255, 0), 15); // Green 232 colorWipe(strip.Color( 0, 0, 255), 15); // Blue 233 colorWipe(strip.Color(255, 255, 0), 15); // Yellow 234 colorWipe(strip.Color( 0, 0, 0), 10); //off 235 delay(1000); 236 colorWipe(strip.Color(255, 0, 0), 15); // Red 237 colorWipe(strip.Color( 0, 255, 0), 15); // Green 238 colorWipe(strip.Color( 0, 0, 255), 15); // Blue 239 colorWipe(strip.Color(255, 255, 0), 15); // Yellow 240 colorWipe(strip.Color( 0, 0, 0), 10); //off 241 delay(500); 242 243 244 lcd.clear(); 245 lcd.setCursor(0,0); 246 lcd.print("GET READY!"); 247 lcd.setBacklight(TEAL); 248 lcd.setCursor(0,1); 249 lcd.print("* * * * *"); 250 251 delay(randomTime); 252 253 startGame(); 254 } 255} 256 257// Listen for the Players 1,2,3, & 4 buttons to be pressed 258void startGame(){ 259 gameOn = true; // Declare a game currently running 260 startTime = millis(); 261 colorWipe(strip.Color(192,192,192), 0);// silver // Turn on game LED indicating players should press their buttons as quickly as possible 262 263 lcd.clear(); 264 lcd.setCursor(0,0); 265 lcd.print("WHO WAS COUSIN"); 266 lcd.setBacklight(BLUE); 267 lcd.setCursor(0,1); 268 lcd.print("SLOW POKE??"); 269 270 while(p1Done == false || p2Done == false || p3Done == false || p4Done == false){ 271 buttonStateP1 = digitalRead(switchPin1); 272 buttonStateP2 = digitalRead(switchPin2); 273 buttonStateP3 = digitalRead(switchPin3); 274 buttonStateP4 = digitalRead(switchPin4); 275 276 // Listen for Player 1 button to be pressed and set Player 1 as done. 277 if (buttonStateP1 == LOW && p1Done == false) { 278 endTimeP1 = millis(); 279 p1Done = true; 280 } 281 // Listen for Player 2 button to be pressed and set Player 2 as done. 282 if (buttonStateP2 == LOW && p2Done == false) { 283 endTimeP2 = millis(); 284 p2Done = true; 285 } 286 // Listen for Player 3 button to be pressed and set Player 3 as done. 287 if (buttonStateP3 == LOW && p3Done == false) { 288 endTimeP3 = millis(); 289 p3Done = true; 290 } 291 // Listen for Player 4 button to be pressed and set Player 4 as done. 292 if (buttonStateP4 == LOW && p4Done == false) { 293 endTimeP4 = millis(); 294 p4Done = true; 295 } 296 } 297 298 colorWipe(strip.Color( 0, 0, 0), 0); //off // Turn off the game LED 299 strip.show(); 300 rainbow(10); // Flowing rainbow cycle along the whole strip 301 endGame(); 302} 303 304void endGame(){ 305 306 finalTimeP1 = (endTimeP1 - startTime); //Calculate how long it took Player 1 to push their button 307 finalTimeP2 = (endTimeP2 - startTime); //Calculate how long it took Player 2 to push their button 308 finalTimeP3 = (endTimeP3 - startTime); //Calculate how long it took Player 3 to push their button 309 finalTimeP4 = (endTimeP4 - startTime); //Calculate how long it took Player 4 to push their button 310 311 // Run if Player 1 lost the round 312 if (finalTimeP1 > finalTimeP2 && finalTimeP1 > finalTimeP3 && finalTimeP1 > finalTimeP4){ 313 314 noInterrupts(); 315 musicPlayer.stopPlaying(); 316 delay(100); 317 interrupts(); 318 delay(100); 319 Player1StepMode(); 320 321 Player1LCDMode(); 322 323 Player1StepHome(); 324 musicPlayer.playFullFile("track006.mp3"); 325 theaterChaseRainbow(50); 326 resetVariables(); 327 } 328 329 // Run if Player 2 lost the round 330 else if (finalTimeP2 > finalTimeP1 && finalTimeP2 > finalTimeP3 && finalTimeP2 > finalTimeP4){ 331 332 noInterrupts(); 333 musicPlayer.stopPlaying(); 334 delay(100); 335 interrupts(); 336 delay(100); 337 Player2StepMode(); 338 339 Player2LCDMode(); 340 341 Player2StepHome(); 342 theaterChaseRainbow(50); 343 resetVariables(); 344 } 345 346 // Run if Player 3 lost the round 347 else if (finalTimeP3 > finalTimeP1 && finalTimeP3 > finalTimeP2 && finalTimeP3 > finalTimeP4){ 348 349 noInterrupts(); 350 musicPlayer.stopPlaying(); 351 delay(100); 352 interrupts(); 353 delay(100); 354 Player3StepMode(); 355 356 Player3LCDMode(); 357 358 Player3StepHome(); 359 theaterChaseRainbow(50); 360 resetVariables(); 361 } 362 363 // Run if Player 4 lost the round 364 else if (finalTimeP4 > finalTimeP1 && finalTimeP4 > finalTimeP2 && finalTimeP4 > finalTimeP3){ 365 366 noInterrupts(); 367 musicPlayer.stopPlaying(); 368 delay(100); 369 interrupts(); 370 delay(100); 371 Player4StepMode(); 372 373 Player4LCDMode(); 374 375 Player4StepHome(); 376 theaterChaseRainbow(50); 377 resetVariables(); 378 } 379 380 //This assigns a loser in a tie 381 else if (finalTimeP1 == finalTimeP2 && finalTimeP1 > finalTimeP3 && finalTimeP1 > finalTimeP4){ 382 noInterrupts(); 383 musicPlayer.stopPlaying(); 384 delay(100); 385 interrupts(); 386 delay(100); 387 Player2StepMode(); 388 389 Player2LCDMode(); 390 391 Player2StepHome(); 392 theaterChaseRainbow(50); 393 resetVariables(); 394 } 395 396 //This assigns a loser in a tie 397 else if (finalTimeP1 == finalTimeP3 && finalTimeP1 > finalTimeP2 && finalTimeP1 > finalTimeP4){ 398 noInterrupts(); 399 musicPlayer.stopPlaying(); 400 delay(100); 401 interrupts(); 402 delay(100); 403 Player1StepMode(); 404 405 Player1LCDMode(); 406 407 Player1StepHome(); 408 musicPlayer.playFullFile("track006.mp3"); 409 theaterChaseRainbow(50); 410 resetVariables(); 411 } 412 413 //This assigns a loser in a tie 414 else if (finalTimeP1 == finalTimeP4 && finalTimeP1 > finalTimeP2 && finalTimeP1 > finalTimeP3){ 415 416 noInterrupts(); 417 musicPlayer.stopPlaying(); 418 delay(100); 419 interrupts(); 420 delay(100); 421 Player4StepMode(); 422 423 Player4LCDMode(); 424 425 Player4StepHome(); 426 theaterChaseRainbow(50); 427 resetVariables(); 428 } 429 430 //This assigns a loser in a tie 431 else if (finalTimeP2 == finalTimeP3 && finalTimeP2 > finalTimeP1 && finalTimeP2 > finalTimeP4){ 432 noInterrupts(); 433 musicPlayer.stopPlaying(); 434 delay(100); 435 interrupts(); 436 delay(100); 437 Player3StepMode(); 438 439 Player3LCDMode(); 440 441 Player3StepHome(); 442 theaterChaseRainbow(50); 443 resetVariables(); 444 } 445 446 //This assigns a loser in a tie 447 else if (finalTimeP2 == finalTimeP4 && finalTimeP2 > finalTimeP1 && finalTimeP2 > finalTimeP3){ 448 noInterrupts(); 449 musicPlayer.stopPlaying(); 450 delay(100); 451 interrupts(); 452 delay(100); 453 Player2StepMode(); 454 455 Player2LCDMode(); 456 457 Player2StepHome(); 458 theaterChaseRainbow(50); 459 resetVariables(); 460 } 461 462 //This assigns a loser in a tie 463 else if (finalTimeP3 == finalTimeP4 && finalTimeP3 > finalTimeP1 && finalTimeP3 > finalTimeP2){ 464 noInterrupts(); 465 musicPlayer.stopPlaying(); 466 delay(100); 467 interrupts(); 468 delay(100); 469 Player3StepMode(); 470 471 Player3LCDMode(); 472 473 Player3StepHome(); 474 theaterChaseRainbow(50); 475 resetVariables(); 476 } 477 478 //This assigns a loser in a tie 479 else if (finalTimeP1 == finalTimeP2 && finalTimeP1 == finalTimeP3 && finalTimeP1 > finalTimeP4){ 480 noInterrupts(); 481 musicPlayer.stopPlaying(); 482 delay(100); 483 interrupts(); 484 delay(100); 485 Player1StepMode(); 486 487 Player1LCDMode(); 488 489 Player1StepHome(); 490 musicPlayer.playFullFile("track006.mp3"); 491 theaterChaseRainbow(50); 492 resetVariables(); 493 } 494 495 //This assigns a loser in a tie 496 else if (finalTimeP1 == finalTimeP3 && finalTimeP1 == finalTimeP4 && finalTimeP1 > finalTimeP2){ 497 noInterrupts(); 498 musicPlayer.stopPlaying(); 499 delay(100); 500 interrupts(); 501 delay(100); 502 Player3StepMode(); 503 504 Player3LCDMode(); 505 506 Player3StepHome(); 507 theaterChaseRainbow(50); 508 resetVariables(); 509 } 510 511 //This assigns a loser in a tie 512 else if (finalTimeP1 == finalTimeP2 && finalTimeP1 == finalTimeP4 && finalTimeP1 > finalTimeP3){ 513 noInterrupts(); 514 musicPlayer.stopPlaying(); 515 delay(100); 516 interrupts(); 517 delay(100); 518 Player2StepMode(); 519 520 Player2LCDMode(); 521 522 Player2StepHome(); 523 theaterChaseRainbow(50); 524 resetVariables(); 525 } 526 527 //This assigns a loser in a tie 528 else if (finalTimeP2 == finalTimeP3 && finalTimeP2 == finalTimeP4 && finalTimeP2 > finalTimeP1){ 529 noInterrupts(); 530 musicPlayer.stopPlaying(); 531 delay(100); 532 interrupts(); 533 delay(100); 534 Player4StepMode(); 535 536 Player4LCDMode(); 537 538 Player4StepHome(); 539 theaterChaseRainbow(50); 540 resetVariables(); 541 } 542 543 //This assigns a loser in a tie 544 else if (finalTimeP1 == finalTimeP2 && finalTimeP1 == finalTimeP3 && finalTimeP1 == finalTimeP4){ 545 noInterrupts(); 546 musicPlayer.stopPlaying(); 547 delay(100); 548 interrupts(); 549 delay(100); 550 Player1StepMode(); 551 552 Player1LCDMode(); 553 554 Player1StepHome(); 555 musicPlayer.playFullFile("track006.mp3"); 556 theaterChaseRainbow(50); 557 resetVariables(); 558 } 559} 560 561//Moves shot glass to loser 562void Player1StepMode(){ 563 digitalWrite(en,LOW); //enabled stepper 564 digitalWrite(dir,LOW); //pin low to move "forward" 565 566 for(x= 0; x<50; x++) //Loop the forward stepping 567 { 568 digitalWrite(stp,HIGH); //Trigger one step forward 569 delayMicroseconds(300); 570 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 571 delayMicroseconds(300); 572 } 573 for(x= 0; x<10550; x++) //Loop the forward stepping 574 { 575 digitalWrite(stp,HIGH); //Trigger one step forward 576 delayMicroseconds(175); 577 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 578 delayMicroseconds(175); 579 } 580 for(x= 0; x<50; x++) //Loop the forward stepping 581 { 582 digitalWrite(stp,HIGH); //Trigger one step forward 583 delayMicroseconds(300); 584 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 585 delayMicroseconds(300); 586 } 587 delay(750); 588 589 for(x= 0; x<50; x++) 590 { 591 digitalWrite(stp,HIGH); //Trigger one step forward 592 delayMicroseconds(300); 593 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 594 delayMicroseconds(300); 595 } 596 for(x= 0; x<4000; x++) 597 { 598 digitalWrite(stp,HIGH); //Trigger one step forward 599 delayMicroseconds(175); 600 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 601 delayMicroseconds(175); 602 } 603 604 for(x= 0; x<50; x++) 605 { 606 digitalWrite(stp,HIGH); //Trigger one step forward 607 delayMicroseconds(300); 608 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 609 delayMicroseconds(300); 610 } 611 delay(750); 612 613 digitalWrite(dir,HIGH); //Pull direction pin high to move "reverse" 614 for(x= 0; x<50; x++) //Loop the stepping 615 { 616 digitalWrite(stp,HIGH); //Trigger one step forward/ 617 delayMicroseconds(300); 618 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 619 delayMicroseconds(300); 620 } 621 for(x= 0; x<12050; x++) //Loop the stepping 622 { 623 digitalWrite(stp,HIGH); //Trigger one step forward/ 624 delayMicroseconds(175); 625 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 626 delayMicroseconds(175); 627 } 628 for(x= 0; x<50; x++) //Loop the stepping 629 { 630 digitalWrite(stp,HIGH); //Trigger one step forward/ 631 delayMicroseconds(300); 632 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 633 delayMicroseconds(300); 634 } 635 delay(1); 636} 637 638//Moves shot glass to loser 639void Player2StepMode() 640{ 641 digitalWrite(en,LOW); //enabled stepper 642 digitalWrite(dir, LOW); //Pull direction pin low to move "forward" 643 644 for(x= 0; x<50; x++) //Loop the forward stepping 645 { 646 digitalWrite(stp,HIGH); //Trigger one step forward 647 delayMicroseconds(300); 648 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 649 delayMicroseconds(300); 650 } 651 652 for(x= 0; x<10550; x++) //Loop the forward stepping 653 { 654 digitalWrite(stp,HIGH); //Trigger one step forward 655 delayMicroseconds(175); 656 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 657 delayMicroseconds(175); 658 } 659 for(x= 0; x<50; x++) //Loop the forward stepping 660 { 661 digitalWrite(stp,HIGH); //Trigger one step forward 662 delayMicroseconds(300); 663 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 664 delayMicroseconds(300); 665 } 666 delay(750); 667 668 digitalWrite(dir, HIGH); //Pull direction pin high to move "reverse" 669 670 for(x= 0; x<50; x++) //Loop the reverse stepping 671 { 672 digitalWrite(stp,HIGH); //Trigger one step forward 673 delayMicroseconds(300); 674 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 675 delayMicroseconds(300); 676 } 677 for(x= 0; x<3950; x++) //Loop the reverse stepping 678 { 679 digitalWrite(stp,HIGH); //Trigger one step forward 680 delayMicroseconds(175); 681 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 682 delayMicroseconds(175); 683 } 684 for(x= 0; x<50; x++) //Loop the reverse stepping 685 { 686 digitalWrite(stp,HIGH); //Trigger one step forward 687 delayMicroseconds(300); 688 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 689 delayMicroseconds(300); 690 } 691 delay(1); 692 693} 694 695//Moves shot glass to loser 696void Player3StepMode() 697{ 698 digitalWrite(en,LOW); //enabled 699 digitalWrite(dir, LOW); //Pull direction pin low to move "forward" 700 701 for(x= 0; x<50; x++) //Loop the forward stepping 702 { 703 digitalWrite(stp,HIGH); //Trigger one step forward 704 delayMicroseconds(300); 705 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 706 delayMicroseconds(300); 707 } 708 for(x= 0; x<10550; x++) //Loop the forward stepping 709 { 710 digitalWrite(stp,HIGH); //Trigger one step forward 711 delayMicroseconds(175); 712 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 713 delayMicroseconds(175); 714 } 715 for(x= 0; x<50; x++) //Loop the forward stepping 716 { 717 digitalWrite(stp,HIGH); //Trigger one step forward 718 delayMicroseconds(300); 719 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 720 delayMicroseconds(300); 721 } 722 723 724 delay(750); 725 726 digitalWrite(dir,LOW); //Pull direction pin low to move "forward" 727 728 for(x= 0; x<50; x++) //Loop the reverse stepping 729 { 730 digitalWrite(stp,HIGH); //Trigger one step forward 731 delayMicroseconds(300); 732 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 733 delayMicroseconds(300); 734 } 735 for(x= 0; x<4000; x++) //Loop the reverse stepping 736 { 737 digitalWrite(stp,HIGH); //Trigger one step forward 738 delayMicroseconds(175); 739 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 740 delayMicroseconds(175); 741 } 742 for(x= 0; x<50; x++) //Loop the reverse stepping 743 { 744 digitalWrite(stp,HIGH); //Trigger one step forward 745 delayMicroseconds(300); 746 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 747 delayMicroseconds(300); 748 } 749 750 delay(750); 751 752 digitalWrite(dir, HIGH); //Pull direction pin high to move "reverse" 753 754 for(x= 0; x<50; x++) //Loop the forward stepping 755 { 756 digitalWrite(stp,HIGH); //Trigger one step forward 757 delayMicroseconds(300); 758 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 759 delayMicroseconds(300); 760 } 761 for(x= 0; x<4000; x++) //Loop the forward stepping 762 { 763 digitalWrite(stp,HIGH); //Trigger one step forward 764 delayMicroseconds(175); 765 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 766 delayMicroseconds(175); 767 } 768 for(x= 0; x<50; x++) //Loop the forward stepping 769 { 770 digitalWrite(stp,HIGH); //Trigger one step forward 771 delayMicroseconds(300); 772 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 773 delayMicroseconds(300); 774 } 775 776 delay(1); 777} 778 779//Moves shot glass to loser 780void Player4StepMode() 781{ 782 digitalWrite(en,LOW); //enabled 783 digitalWrite(dir, LOW); //Pull direction pin low to move "forward" 784 785 for(x= 0; x<50; x++) //Loop the forward stepping 786 { 787 digitalWrite(stp,HIGH); //Trigger one step forward 788 delayMicroseconds(300); 789 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 790 delayMicroseconds(300); 791 } 792 for(x= 0; x<6500; x++) //Loop the forward stepping 793 { 794 digitalWrite(stp,HIGH); //Trigger one step forward 795 delayMicroseconds(175); 796 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 797 delayMicroseconds(175); 798 } 799 for(x= 0; x<50; x++) //Loop the forward stepping 800 { 801 digitalWrite(stp,HIGH); //Trigger one step forward 802 delayMicroseconds(300); 803 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 804 delayMicroseconds(300); 805 } 806 807 808 delay(750); 809 810 digitalWrite(dir, LOW); //forward 811 812 for(x= 0; x<50; x++) //Loop the forward stepping 813 { 814 digitalWrite(stp,HIGH); //Trigger one step forward 815 delayMicroseconds(300); 816 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 817 delayMicroseconds(300); 818 } 819 for(x= 0; x<3950; x++) //Loop the forward stepping 820 { 821 digitalWrite(stp,HIGH); //Trigger one step forward 822 delayMicroseconds(175); 823 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 824 delayMicroseconds(175); 825 } 826 for(x= 0; x<50; x++) //Loop the forward stepping 827 { 828 digitalWrite(stp,HIGH); //Trigger one step forward 829 delayMicroseconds(300); 830 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 831 delayMicroseconds(300); 832 } 833 834 delay(750); 835 836 digitalWrite(dir, LOW); //Pull direction pin low to move "forward" 837 838 for(x= 0; x<50; x++) //loop 839 { 840 digitalWrite(stp,HIGH); //Trigger one step forward 841 delayMicroseconds(300); 842 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 843 delayMicroseconds(300); 844 } 845 for(x= 0; x<4000; x++) //loop 846 { 847 digitalWrite(stp,HIGH); //Trigger one step forward 848 delayMicroseconds(175); 849 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 850 delayMicroseconds(175); 851 } 852 for(x= 0; x<50; x++) //loop 853 { 854 digitalWrite(stp,HIGH); //Trigger one step forward 855 delayMicroseconds(300); 856 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 857 delayMicroseconds(300); 858 } 859 860 delay(1); 861} 862 863//LCD & Neopixel function for loser 864void Player1LCDMode(){//RED BUTTON 865 if (! musicPlayer.startPlayingFile("/loser001.mp3")) { 866 while (1); 867 } 868 869 while (musicPlayer.playingMusic) { 870 871 lcd.clear(); 872 lcd.setCursor(0,0); 873 lcd.print("RED PLAYER"); 874 lcd.setBacklight(RED); 875 lcd.setCursor(0,1); 876 lcd.print("DRINK UP"); 877 878 theaterChase(strip.Color(255, 0, 0), 50); // Red, half brightness 879 colorWipe(strip.Color(255, 0, 0), 20); // Red 880 colorWipe(strip.Color( 0, 0, 0), 20); // off 881 theaterChase(strip.Color(255, 0, 0), 50); // Red, half brightness 882 colorWipe(strip.Color(255, 0, 0), 20); // Red 883 colorWipe(strip.Color( 0, 0, 0), 20); // off 884 theaterChase(strip.Color(255, 0, 0), 50); // Red, half brightness 885 colorWipe(strip.Color( 0, 0, 0), 0); //off // Turn off the game LED 886 strip.show(); 887 } 888 musicPlayer.softReset(); 889 delay(500); 890 lcd.clear(); //clears previous data in display 891 lcd.print(" DRINKING GAME"); 892 lcd.setCursor(0,1); //set invisible cursor to the first column (column 0), second line (line 1) 893 lcd.print(" FOR THE BRAVE"); 894 lcd.setBacklight(WHITE); 895 delay(1000); 896} 897 898//LCD & Neopixel function for loser 899void Player2LCDMode(){//BLUE BUTTON 900 901 if (! musicPlayer.startPlayingFile("/loser004.mp3")) { 902 while (1); 903 } 904 905 while (musicPlayer.playingMusic) { 906 907 lcd.clear(); 908 lcd.setCursor(0,0); 909 lcd.print("BLUE PLAYER"); 910 lcd.setBacklight(BLUE); 911 lcd.setCursor(0,1); 912 lcd.print("SHOOT IT!"); 913 914 theaterChase(strip.Color(0,0,255), 50); // blue, half brightness 915 colorWipe(strip.Color(0,0,255), 20); // blue 916 colorWipe(strip.Color( 0, 0, 0), 20); // off 917 theaterChase(strip.Color(0,0,255), 50); // blue, half brightness 918 colorWipe(strip.Color(0,0,255), 20); // blue 919 colorWipe(strip.Color( 0, 0, 0), 20); // off 920 theaterChase(strip.Color(0,0,255), 50); // blue, half brightness 921 colorWipe(strip.Color( 0, 0, 0), 0); //off // Turn off the game LED 922 strip.show(); 923 } 924 musicPlayer.softReset(); 925 delay(500); 926 lcd.clear(); //clears previous data in display 927 lcd.print(" DRINKING GAME"); 928 lcd.setCursor(0,1); //set invisible cursor to the first column (column 0), second line (line 1) 929 lcd.print(" FOR THE BRAVE"); 930 lcd.setBacklight(WHITE); 931 delay(1000); 932} 933 934//LCD & Neopixel function for loser 935void Player3LCDMode(){//GREEN BUTTON 936 937 if (! musicPlayer.startPlayingFile("/loser002.mp3")) { 938 while (1); 939 } 940 941 while (musicPlayer.playingMusic) { 942 943 lcd.clear(); 944 lcd.setCursor(0,0); 945 lcd.print("GREEN PLAYER"); 946 lcd.setBacklight(GREEN); 947 lcd.setCursor(0,1); 948 lcd.print("DRINK UP"); 949 950 theaterChase(strip.Color(0,128,0), 50); // green, half brightness 951 colorWipe(strip.Color(0,128,0), 20); // green 952 colorWipe(strip.Color( 0, 0, 0), 20); // off 953 theaterChase(strip.Color(0,128,0), 50); // green, half brightness 954 colorWipe(strip.Color(0,128,0), 20); // green 955 colorWipe(strip.Color( 0, 0, 0), 20); // off 956 theaterChase(strip.Color(0,128,0), 50); // green, half brightness 957 colorWipe(strip.Color( 0, 0, 0), 0); //off // Turn off the game LED 958 strip.show(); 959 } 960 musicPlayer.softReset(); 961 delay(500); 962 lcd.clear(); //clears previous data in display 963 lcd.print(" DRINKING GAME"); 964 lcd.setCursor(0,1); //set invisible cursor to the first column (column 0), second line (line 1) 965 lcd.print(" FOR THE BRAVE"); 966 lcd.setBacklight(WHITE); 967 delay(1000); 968} 969 970//LCD & Neopixel function for loser 971void Player4LCDMode(){//YELLOW BUTTON 972 973 if (! musicPlayer.startPlayingFile("/loser003.mp3")) { 974 while (1); 975 } 976 977 while (musicPlayer.playingMusic) { 978 979 lcd.clear(); 980 lcd.setCursor(0,0); 981 lcd.print("YELLOW PLAYER"); 982 lcd.setBacklight(YELLOW); 983 lcd.setCursor(0,1); 984 lcd.print("SHOOT IT!"); 985 986 theaterChase(strip.Color(255,255,0), 50); // yellow, half brightness 987 colorWipe(strip.Color(255,255,0), 20); // yellow 988 colorWipe(strip.Color( 0, 0, 0), 20); // off 989 theaterChase(strip.Color(255,255,0), 50); // yellow, half brightness 990 colorWipe(strip.Color(255,255,0), 20); // yellow 991 colorWipe(strip.Color( 0, 0, 0), 20); // off 992 theaterChase(strip.Color(255,255,0), 50); // yellow, half brightness 993 colorWipe(strip.Color( 0, 0, 0), 0); //off // Turn off the game LED 994 strip.show(); 995 } 996 musicPlayer.softReset(); 997 delay(500); 998 lcd.clear(); //clears previous data in display 999 lcd.print(" DRINKING GAME"); 1000 lcd.setCursor(0,1); //set invisible cursor to the first column (column 0), second line (line 1) 1001 lcd.print(" FOR THE BRAVE"); 1002 lcd.setBacklight(WHITE); 1003 delay(1000); 1004} 1005 1006//Moves shot glass back to home position 1007void Player1StepHome() 1008{ 1009 //Red Player Stepping 1010 digitalWrite(dir, HIGH); //Pull direction pin high to move "reverse" 1011 1012 for(x= 0; x<2600; x++) //Loop the forward stepping 1013 { 1014 digitalWrite(stp,HIGH); //Trigger one step forward 1015 delayMicroseconds(300); 1016 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 1017 delayMicroseconds(300); 1018 } 1019} 1020 1021//Moves shot glass back to home position 1022void Player2StepHome() 1023{ 1024 //Blue Player Stepping 1025 digitalWrite(dir, HIGH); //Pull direction pin high to move "reverse" 1026 1027 for(x= 0; x<6600; x++) //Loop the forward stepping 1028 { 1029 digitalWrite(stp,HIGH); //Trigger one step forward 1030 delayMicroseconds(300); 1031 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 1032 delayMicroseconds(300); 1033 } 1034} 1035 1036//Moves shot glass back to home position 1037void Player3StepHome() 1038{ 1039 //Green Player Stepping 1040 digitalWrite(dir, HIGH); //Pull direction pin high to move "reverse" 1041 1042 for(x= 0; x<10650; x++) //Loop the forward stepping 1043 { 1044 digitalWrite(stp,HIGH); //Trigger one step forward 1045 delayMicroseconds(300); 1046 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 1047 delayMicroseconds(300); 1048 } 1049} 1050 1051//Moves shot glass back to home position 1052void Player4StepHome() 1053{ 1054 //Yellow Player Stepping 1055 digitalWrite(dir, HIGH); //Pull direction pin high to move "reverse" 1056 1057 for(x= 0; x<14750; x++) //Loop the forward stepping 1058 { 1059 digitalWrite(stp,HIGH); //Trigger one step forward 1060 delayMicroseconds(300); 1061 digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again 1062 delayMicroseconds(300); 1063 } 1064} 1065 1066//Neopixel effect 1067void colorWipe(uint32_t color, int wait) { 1068 for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip... 1069 strip.setPixelColor(i, color); // Set pixel's color (in RAM) 1070 strip.show(); // Update strip to match 1071 delay(wait); // Pause for a moment 1072 } 1073} 1074 1075//Neopixel effect 1076void rainbow(int wait) { 1077 1078 for(long firstPixelHue = 0; firstPixelHue < 1*65536; firstPixelHue += 256) { 1079 for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip... 1080 1081 int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels()); 1082 1083 strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue))); 1084 } 1085 strip.show(); // Update strip with new contents 1086 delay(wait); // Pause for a moment 1087 } 1088} 1089 1090//Neopixel effect 1091void theaterChase(uint32_t color, int wait) { 1092 for(int a=0; a<20; a++) { // Repeat 10 times... 1093 for(int b=0; b<3; b++) { // 'b' counts from 0 to 2... 1094 strip.clear(); // Set all pixels in RAM to 0 (off) 1095 1096 for(int c=b; c<strip.numPixels(); c += 3) { 1097 strip.setPixelColor(c, color); // Set pixel 'c' to value 'color' 1098 } 1099 strip.show(); // Update strip with new contents 1100 delay(wait); // Pause for a moment 1101 } 1102 } 1103} 1104 1105//Neopixel effect 1106void theaterChaseRainbow(int wait) { 1107 int firstPixelHue = 0; // First pixel starts at red (hue 0) 1108 for(int a=0; a<15; a++) { // Repeat 30 times... 1109 for(int b=0; b<3; b++) { // 'b' counts from 0 to 2... 1110 strip.clear(); // Set all pixels in RAM to 0 (off) 1111 1112 for(int c=b; c<strip.numPixels(); c += 3) { 1113 1114 int hue = firstPixelHue + c * 65536L / strip.numPixels(); 1115 uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB 1116 strip.setPixelColor(c, color); // Set pixel 'c' to value 'color' 1117 } 1118 strip.show(); // Update strip with new contents 1119 delay(wait); // Pause for a moment 1120 firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames 1121 } 1122 } 1123} 1124 1125//SD Card on musicmaker shield 1126void printDirectory(File dir, int numTabs) { 1127 while(true) { 1128 1129 File entry = dir.openNextFile(); 1130 if (! entry) { 1131 // no more files 1132 //Serial.println("**nomorefiles**"); 1133 break; 1134 } 1135 for (uint8_t i=0; i<numTabs; i++) { 1136 Serial.print('\ '); 1137 } 1138 Serial.print(entry.name()); 1139 if (entry.isDirectory()) { 1140 Serial.println("/"); 1141 printDirectory(entry, numTabs+1); 1142 } else { 1143 // files have sizes, directories do not 1144 Serial.print("\ \ "); 1145 Serial.println(entry.size(), DEC); 1146 } 1147 entry.close(); 1148 } 1149} 1150 1151//Resets back to initial state 1152void resetVariables(){ 1153 digitalWrite(en,HIGH);//disabled 1154 musicPlayer.softReset(); 1155 strip.clear(); 1156 strip.show(); 1157 buttonStateP1 = 0; 1158 buttonStateP2 = 0; 1159 buttonStateP3 = 0; 1160 buttonStateP4 = 0; 1161 lastButtonStateP1 = 0; 1162 lastButtonStateP2 = 0; 1163 lastButtonStateP3 = 0; 1164 lastButtonStateP4 = 0; 1165 startButtonState = HIGH; 1166 buttonStateP1 = HIGH; 1167 buttonStateP2 = HIGH; 1168 buttonStateP3 = HIGH; 1169 buttonStateP4 = HIGH; 1170 allDone = false; 1171 gameOn = false; 1172 p1Done = false; 1173 p2Done = false; 1174 p3Done = false; 1175 p4Done = false; 1176 randomTime = 0; 1177 startTime = 0; 1178 p1Done = false; 1179 p2Done = false; 1180 p3Done = false; 1181 p4Done = false; 1182 finalTimeP1 = 0; 1183 finalTimeP2 = 0; 1184 finalTimeP3 = 0; 1185 finalTimeP4 = 0; 1186} 1187 1188 1189 1190
Downloadable files
Drinking Game
Drinking Game
Drinking Game
Drinking Game
Comments
Only logged in users can leave comments