Project showcase
Drinking Game for the Brave

Drinking Game for the Brave © GPL3+

This is a 4-player reaction game penalizing the loser with a shot of liquor delivered to them on a conveyor.

  • 1,887 views
  • 0 comments
  • 14 respects

Components and supplies

A000066 iso both
Arduino UNO & Genuino UNO
The brains of the operation
×1
SparkFun EasyDriver - Stepper Motor Driver
Driver for stepper motor
×1
1586 00
Adafruit NeoPixel Ring: WS2812 5050 RGB LED
4 Neopixel rings mounted around arcade buttons
×4
arcade style buttons
I used 4 different colors- red, blue, green , & yellow
×4
Rugged Metal Pushbutton with Blue LED Ring - 16mm Blue Momentary
Start button mounted on front panel
×1
1788 00
Adafruit Arduino MP3 Shield
Mounts to Arduino
×1
Adafruit Stereo 20W Class D Audio Amplifier- MAX9744
Audio amplifier
×1
Adafruit RGB backlight negative LCD 16x2 + extras - RGB on black
RGB LCD display
×1
Adafruit I2C Controlled + Keypad Shield Kit for 16x2 LCD
I2C for display only used 2 wires
×1
Adafruit Acrylic Stand for 16x2 Character LCD
I used pieces of this as a bezel for the lcd display
×1
Nema17 59Ncm 2A 1.8°4-lead 48mm Stepper Motor
Stepper Motor
×1
MEAN WELL RD-65A Dual Output Enclosed Power Supply 5V 8 Amp and 12V
5V powers the Arduino & Neopixels, 12V powers the stepper driver & audio amp
×1
URBEST Inlet Module Plug 5A Fuse Switch Male Power Socket 10A 250V 3 Pin IEC320 C14
Back panel mount power plug socket and switch
×1
Gardner Bender GSW-61 Electrical Rotary Switch, SPST
Used for the front panel on/off switch
×1
Acoustic Audio AA321B Mountable Indoor Speakers 400 Watts Black Bookshelf Pair
pair of speakers
×1
Panel Mount 1K potentiometer (Breadboard Friendly) - 1K Linear
Mounted on front panel for audio volume
×1
Screen%20shot%202016 04 25%20at%202.57.01%20pm
Makerbeam
I used MakerBeam XL 1000mm length & 100mm length to make the box
×1
Machifit 100-1000mm Black 2040 V-Slot Aluminum Profile Extrusion
Used for the conveyor rail
×1
Machfit Aluminum Nema 17 Stepper Motor Mount Plate
Mount for stepper motor
×1
5M GT2 Timing Belt With 16T GT2 Timing Pulley
timing belt & pulley
×1
Machifit Aluminum Idler Pulley Plate
Mount for idler pulley
×1
Machifit V-Slot V Gantry Plat Special Slide Plate Five Roulette for 2040 Aluminum Profile
slides on rail connected to timing belt
×1
BIQU Big Aluminum Alloy Gantry Plate+ Plastic Pulley Wheel with Bearing Set for 3D Printer
mounted on top of V-slot gantry for larger platform for shot glass
×1
Acrylic Sheets- 3 mm Thick
Panels: 4-108 mm Wide, 1008 mm Long; 2-108 mm Wide, 108 mm Long
×1

Necessary tools and machines

09507 01
Soldering iron (generic)
soldering components
26w6260 40
Multitool, Screwdriver
for mounting standoffs/hardware
70y8518 40
Drill / Driver, Cordless
Cutting holes in plexiglass
jig saw
cut out for display

About this project

Quick demonstration

This project is a reaction game. The object consists of 4 players waiting for a light to illuminate and once illuminated players attempt to hit their button faster than their opponents. The loser is notified with visual & audio effects as well as a shot glass brought to them on a conveyor belt.

I am a novice in the world of electronics and coding. This was a spare time hobby and with a little determination I was able to finish it over the course of a month or so.

The box is constructed with 3mm plexiglass using 15mm x 15mm extruded aluminum beams as the frame. The conveyor system for the shot glass consists of a 20mm x 40mm extruded aluminum rail mounted above the box. A stepper motor and timing belt is mounted to the rail. A gantry plate moves along the rail with V-groove pulleys.

An Arduino Uno was chosen for the micro-controller. It controls a stepper driver, an MP3 player, and NeoPixels in the game code.

I used a free text to speech website to create audio files. I edited them with background music using Audacity and saved them to the SD card on the MP3 player. The audio clips are used as an introduction in the beginning of the game and also used in combination with NeoPixel lighting effects and the stepper motor to inform the loser to take their punishment in the form of a shot.

Code

Drinking Game For The BraveArduino
/***************************************************************
* GAME 
* 4 players
* Drinking Game for the Brave - 08/01/2019
* This game consists of 4 players waiting for a light to illuminate and once illuminated
* players attempt to hit their button faster than their opponents. The loser is notified with visual
* & audio effects as well as a shot glass brought to them on a conveyer belt.
* This code is a monster mashed hodge podge from multiple original sources & example sketches. 
* I edited what I needed to make this game work. 
* I don't know what I'm doing but I'm learning the hard way!
* Thank you to Lotte and Arjan for their inspiring 2 person reaction game, and to Adafruit & SparkFun for
* both being wonderful resources in this amazing journey!
*****************************************************************/

#include <Wire.h>//This library allows you to communicate with I2C.
#include <Adafruit_RGBLCDShield.h> //library for Adafruit RGB LCD Shield
#include <Adafruit_NeoPixel.h> // library for Neopixels
#include <SPI.h>//Serial Peripheral Interface (SPI) is an interface bus commonly used to send data
//between microcontrollers and small peripherals such as shift registers, sensors, and SD cards. 
//It uses separate clock & data lines, along with a select line to choose the device you wish to talk to.
#include <Adafruit_VS1053.h> //library for Adafruit music maker shield.
#include <SD.h>//The SD library allows for reading from and writing to SD cards.

#define SHIELD_RESET  -1      // VS1053 reset pin (unused!)
#define SHIELD_CS     7      // VS1053 chip select pin (output)
#define SHIELD_DCS    6      // VS1053 Data/command select pin (output)

#define CARDCS 4     // Card chip select pin
// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define DREQ 3       // VS1053 Data request, ideally an Interrupt pin

Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);
  
#define LED_PIN 10 //Neopixel rings
#define LED_COUNT 24 //24 leds on  each ring
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);


Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();

//RGB LCD Shield 
#define RED 0x1
#define YELLOW 0x3
#define GREEN 0x2
#define TEAL 0x6
#define BLUE 0x4
#define VIOLET 0x5
#define WHITE 0x7

//Declare pin functions on Arduino for the SparkFun EasyDriver Stepper Motor Driver
const int stp = 8;
const int dir = 9;
const int en = A2;


//Declare variables for functions (Neopixel effects)
char user_input;
int x;
int y;
int state;

const int switchStart = A0; //Start button
const int switchPin1 = 0; //Player 1 button (red)
const int switchPin2 = 5; //Player 2 button (blue)
const int switchPin3 = 2; //Player 3 button (green)
const int switchPin4 = A1; //Player 4 button (yellow)




int buttonStateP1 = 0; //Player 1 button tracking
int buttonStateP2 = 0; //Player 2 button tracking
int buttonStateP3 = 0; //Player 3 button tracking
int buttonStateP4 = 0; //Player 4 button tracking
int lastButtonStateP1 = 0; // Player 1 last button state (used to detect a button press)
int lastButtonStateP2 = 0; // Player 2 last button state (used to detect a button press)
int lastButtonStateP3 = 0; // Player 3 last button state (used to detect a button press)
int lastButtonStateP4 = 0; // Player 4 last button state (used to detect a button press)
int scoreP1 = 0; // Player 1 score tracking
int scoreP2 = 0; // Player 2 score tracking
int scoreP3 = 0; // Player 3 score tracking
int scoreP4 = 0; // Player 4 score tracking
boolean allDone = false; // Used to see if all players have pressed their buttons
boolean gameOn = false; // Keep track if the game is going on or not
boolean startButtonState = HIGH; // Start button initalization
 
boolean p1Done = false; // Keep track of Player 1's button press
boolean p2Done = false; // Keep track of Player 2's button press
boolean p3Done = false; // Keep track of Player 3's button press
boolean p4Done = false; // Keep track of Player 4's button press

long randomTime; // Hold the random time between the start of the game and the indicator light coming back on
long startTime; // When did the game start
long endTimeP1; // When did Player 1 press their button
long endTimeP2; // When did Player 2 press their button
long endTimeP3; // When did Player 3 press their button
long endTimeP4; // When did Player 4 press their button

float finalTimeP1; // Time elapsed between start of the game and Player 1 pressing their button
float finalTimeP2; // Time elapsed between start of the game and Player 2 pressing their button
float finalTimeP3; // Time elapsed between start of the game and Player 3 pressing their button
float finalTimeP4; // Time elapsed between start of the game and Player 4 pressing their button

void setup() {
  
  strip.begin();// INITIALIZE NeoPixel strip object (REQUIRED)
  strip.show();            // Turn OFF all pixels ASAP
  strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
  theaterChaseRainbow(50); // Rainbow-enhanced theaterChase variant
  strip.clear();
  strip.show();
  
  Serial.begin(9600);
  Serial.println("Adafruit VS1053 Library Test");

  // initialize the music player
  if (! musicPlayer.begin()) { // initialise the music player
     Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
     while (1);
  }
  Serial.println(F("VS1053 found"));

  //musicPlayer.sineTest(0x44, 500);    // Make a tone to indicate VS1053 is working
  
 
  if (!SD.begin(CARDCS)) {
    Serial.println(F("SD failed, or not present"));
    while (1);  // don't do anything more
  }
  Serial.println("SD OK!");
  
  printDirectory(SD.open("/"), 0);

  // Set volume for left, right channels. lower numbers == louder volume!
  musicPlayer.setVolume(20,20);

  
  // This option uses a pin interrupt. No timers required! But DREQ
  // must be on an interrupt pin. For Uno/Duemilanove/Diecimilla
  // that's Digital #2 or #3
  // See http://arduino.cc/en/Reference/attachInterrupt for other pins
  // *** This method is preferred
  if (! musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT))
    Serial.println(F("DREQ pin is not an interrupt pin"));
  

  pinMode(stp, OUTPUT);
  pinMode(dir, OUTPUT);
  pinMode(en, OUTPUT);
  pinMode(switchStart, INPUT_PULLUP);
  pinMode(switchPin1, INPUT_PULLUP);
  pinMode(switchPin2, INPUT_PULLUP);
  pinMode(switchPin3, INPUT_PULLUP);
  pinMode(switchPin4, INPUT_PULLUP);
  
  digitalWrite(en,HIGH);//disables stepper
  
  lcd.begin(16, 2); //lcd size 2 lines, 16 characters
  lcd.clear(); //clears previous data in display
  lcd.print(" DRINKING GAME");
  lcd.setCursor(0,1); //set invisible cursor to the first column (column 0), second line (line 1)
  lcd.print(" FOR THE BRAVE");
  lcd.setBacklight(WHITE);
  
  musicPlayer.playFullFile("heathens.mp3");//Intro audio
} 

void loop(){
  
  startButtonState = digitalRead(switchStart); // Listen for the start button to be pressed
  buttonStateP1 = digitalRead(switchPin1);
  buttonStateP2 = digitalRead(switchPin2);
  buttonStateP3 = digitalRead(switchPin3);
  buttonStateP4 = digitalRead(switchPin4);
  
  // if the start button has been pressed and there is no game already running, begin the game
  if (startButtonState == LOW && gameOn == false){
   Random();
  }
  
  //secret function to play Led Zeppelin album.
  if (buttonStateP1 == LOW && buttonStateP4 == LOW && gameOn == false) {
    musicPlayer.playFullFile("zeppelin.mp3"); 
  }
  
  //led effect when button pressed while game is not going.
  else if (buttonStateP1 == LOW && gameOn == false) {
   colorWipe(strip.Color(255,   0,   0), 10); // Red
   colorWipe(strip.Color(  0,   0,   0), 10); // off
   strip.show();
  }
  
  //led effect when button pressed while game is not going.
  else if (buttonStateP2 == LOW && gameOn == false) {
   colorWipe(strip.Color(0,0,255), 10); // blue
   colorWipe(strip.Color(  0,   0,   0), 10); // off
   strip.show();
  }
  
  //led effect when button pressed while game is not going.
  else if (buttonStateP3 == LOW && gameOn == false) {
   colorWipe(strip.Color(0,128,0), 10); // green
   colorWipe(strip.Color(  0,   0,   0), 10); // off
   strip.show();
  }
  
  //led effect when button pressed while game is not going.
  else if (buttonStateP4 == LOW && gameOn == false) {
   colorWipe(strip.Color(255,255,0), 10); // yellow
   colorWipe(strip.Color(  0,   0,   0), 10); // off
   strip.show();
  }
}


// Generate a random amount of time to delay between the beginning of the game until the LED comes back on
void Random(){
  
  if (! musicPlayer.startPlayingFile("/intense1.mp3")) {
  //  Serial.println("Could not open file intense1.mp3");
  while (1);
  }

  while (musicPlayer.playingMusic) {

  randomTime = random(4,10);
  randomTime = randomTime*1000;
  
  //Neopixel effects while waiting to press button
  colorWipe(strip.Color(255,   0,   0), 15); // Red
  colorWipe(strip.Color(  0, 255,   0), 15); // Green
  colorWipe(strip.Color(  0,   0, 255), 15); // Blue
  colorWipe(strip.Color(255, 255,   0), 15); // Yellow
  colorWipe(strip.Color(  0,   0,   0), 10); //off
  delay(1000);
  colorWipe(strip.Color(255,   0,   0), 15); // Red
  colorWipe(strip.Color(  0, 255,   0), 15); // Green
  colorWipe(strip.Color(  0,   0, 255), 15); // Blue
  colorWipe(strip.Color(255, 255,   0), 15); // Yellow
  colorWipe(strip.Color(  0,   0,   0), 10); //off
  delay(500);
  
  
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("GET READY!");
  lcd.setBacklight(TEAL);
  lcd.setCursor(0,1);
  lcd.print("* * * * *");
  
  delay(randomTime);
  
  startGame();
 } 
}

// Listen for the Players 1,2,3, & 4 buttons to be pressed
void startGame(){
  gameOn = true; // Declare a game currently running
  startTime = millis();
  colorWipe(strip.Color(192,192,192), 0);// silver // Turn on game LED indicating players should press their buttons as quickly as possible

  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("WHO WAS COUSIN");
  lcd.setBacklight(BLUE);
  lcd.setCursor(0,1);
  lcd.print("SLOW POKE??");
  
  while(p1Done == false || p2Done == false || p3Done == false || p4Done == false){
    buttonStateP1 = digitalRead(switchPin1);
    buttonStateP2 = digitalRead(switchPin2);
    buttonStateP3 = digitalRead(switchPin3);
    buttonStateP4 = digitalRead(switchPin4);
    
    // Listen for Player 1 button to be pressed and set Player 1 as done.
    if (buttonStateP1 == LOW && p1Done == false) {
      endTimeP1 = millis();
      p1Done = true;     
    }
    // Listen for Player 2 button to be pressed and set Player 2 as done.
    if (buttonStateP2 == LOW && p2Done == false) {
      endTimeP2 = millis();
      p2Done = true;  
    }
    // Listen for Player 3 button to be pressed and set Player 3 as done.
    if (buttonStateP3 == LOW && p3Done == false) {
      endTimeP3 = millis();
      p3Done = true;
    }
    // Listen for Player 4 button to be pressed and set Player 4 as done.
    if (buttonStateP4 == LOW && p4Done == false) {
      endTimeP4 = millis();
      p4Done = true;
    }
  }
  
  colorWipe(strip.Color(  0,   0,   0), 0); //off // Turn off the game LED
  strip.show();
  rainbow(10); // Flowing rainbow cycle along the whole strip
  endGame();
}

void endGame(){
  
  finalTimeP1 = (endTimeP1 - startTime); //Calculate how long it took Player 1 to push their button
  finalTimeP2 = (endTimeP2 - startTime); //Calculate how long it took Player 2 to push their button
  finalTimeP3 = (endTimeP3 - startTime); //Calculate how long it took Player 3 to push their button
  finalTimeP4 = (endTimeP4 - startTime); //Calculate how long it took Player 4 to push their button
 
 // Run if Player 1 lost the round
  if (finalTimeP1 > finalTimeP2 && finalTimeP1 > finalTimeP3 && finalTimeP1 > finalTimeP4){
   
   noInterrupts();
   musicPlayer.stopPlaying();
   delay(100);
   interrupts();
   delay(100);
   Player1StepMode();
   
   Player1LCDMode();
  
   Player1StepHome();
   musicPlayer.playFullFile("track006.mp3");
   theaterChaseRainbow(50);
   resetVariables();
  }

  // Run if Player 2 lost the round
  else if (finalTimeP2 > finalTimeP1 && finalTimeP2 > finalTimeP3 && finalTimeP2 > finalTimeP4){
   
   noInterrupts();
   musicPlayer.stopPlaying();
   delay(100);
   interrupts();
   delay(100);
   Player2StepMode();

   Player2LCDMode();
   
   Player2StepHome();
   theaterChaseRainbow(50);
   resetVariables();
  }
  
  // Run if Player 3 lost the round
  else if (finalTimeP3 > finalTimeP1 && finalTimeP3 > finalTimeP2 && finalTimeP3 > finalTimeP4){
   
   noInterrupts();
   musicPlayer.stopPlaying();
   delay(100);
   interrupts();
   delay(100);
   Player3StepMode();
  
   Player3LCDMode();
   
   Player3StepHome();
   theaterChaseRainbow(50);
   resetVariables();
  }
  
  // Run if Player 4 lost the round
  else if (finalTimeP4 > finalTimeP1 && finalTimeP4 > finalTimeP2 && finalTimeP4 > finalTimeP3){
  
   noInterrupts();
   musicPlayer.stopPlaying();
   delay(100);
   interrupts();
   delay(100);
   Player4StepMode();
   
   Player4LCDMode();
   
   Player4StepHome();
   theaterChaseRainbow(50);
   resetVariables();
  }
  
  //This assigns a loser in a tie
  else if (finalTimeP1 == finalTimeP2 && finalTimeP1 > finalTimeP3 && finalTimeP1 > finalTimeP4){
   noInterrupts();
   musicPlayer.stopPlaying();
   delay(100);
   interrupts();
   delay(100);
   Player2StepMode();

   Player2LCDMode();
   
   Player2StepHome();
   theaterChaseRainbow(50);
   resetVariables();
  }
  
  //This assigns a loser in a tie
  else if (finalTimeP1 == finalTimeP3 && finalTimeP1 > finalTimeP2 && finalTimeP1 > finalTimeP4){
   noInterrupts();
   musicPlayer.stopPlaying();
   delay(100);
   interrupts();
   delay(100);
   Player1StepMode();
   
   Player1LCDMode();
  
   Player1StepHome();
   musicPlayer.playFullFile("track006.mp3");
   theaterChaseRainbow(50);
   resetVariables();  
  }
  
  //This assigns a loser in a tie
  else if (finalTimeP1 == finalTimeP4 && finalTimeP1 > finalTimeP2 && finalTimeP1 > finalTimeP3){
    
   noInterrupts();
   musicPlayer.stopPlaying();
   delay(100);
   interrupts();
   delay(100);
   Player4StepMode();
   
   Player4LCDMode();
   
   Player4StepHome();
   theaterChaseRainbow(50);
   resetVariables(); 
  }
  
  //This assigns a loser in a tie
  else if (finalTimeP2 == finalTimeP3 && finalTimeP2 > finalTimeP1 && finalTimeP2 > finalTimeP4){
   noInterrupts();
   musicPlayer.stopPlaying();
   delay(100);
   interrupts();
   delay(100);
   Player3StepMode();
  
   Player3LCDMode();
   
   Player3StepHome();
   theaterChaseRainbow(50);
   resetVariables(); 
  }
  
  //This assigns a loser in a tie
  else if (finalTimeP2 == finalTimeP4 && finalTimeP2 > finalTimeP1 && finalTimeP2 > finalTimeP3){ 
   noInterrupts();
   musicPlayer.stopPlaying();
   delay(100);
   interrupts();
   delay(100);
   Player2StepMode();

   Player2LCDMode();
   
   Player2StepHome();
   theaterChaseRainbow(50);
   resetVariables();
  }
  
  //This assigns a loser in a tie
  else if (finalTimeP3 == finalTimeP4 && finalTimeP3 > finalTimeP1 && finalTimeP3 > finalTimeP2){
   noInterrupts();
   musicPlayer.stopPlaying();
   delay(100);
   interrupts();
   delay(100);
   Player3StepMode();
  
   Player3LCDMode();
   
   Player3StepHome();
   theaterChaseRainbow(50);
   resetVariables();
  }
  
  //This assigns a loser in a tie
  else if (finalTimeP1 == finalTimeP2 && finalTimeP1 == finalTimeP3 && finalTimeP1 > finalTimeP4){
   noInterrupts();
   musicPlayer.stopPlaying();
   delay(100);
   interrupts();
   delay(100);
   Player1StepMode();
   
   Player1LCDMode();
  
   Player1StepHome();
   musicPlayer.playFullFile("track006.mp3");
   theaterChaseRainbow(50);
   resetVariables();
  }
  
  //This assigns a loser in a tie
  else if (finalTimeP1 == finalTimeP3 && finalTimeP1 == finalTimeP4 && finalTimeP1 > finalTimeP2){
   noInterrupts();
   musicPlayer.stopPlaying();
   delay(100);
   interrupts();
   delay(100);
   Player3StepMode();
  
   Player3LCDMode();
   
   Player3StepHome();
   theaterChaseRainbow(50);
   resetVariables(); 
  }
 
 //This assigns a loser in a tie
  else if (finalTimeP1 == finalTimeP2 && finalTimeP1 == finalTimeP4 && finalTimeP1 > finalTimeP3){
   noInterrupts();
   musicPlayer.stopPlaying();
   delay(100);
   interrupts();
   delay(100);
   Player2StepMode();

   Player2LCDMode();
   
   Player2StepHome();
   theaterChaseRainbow(50);
   resetVariables(); 
  }
  
  //This assigns a loser in a tie
  else if (finalTimeP2 == finalTimeP3 && finalTimeP2 == finalTimeP4 && finalTimeP2 > finalTimeP1){
   noInterrupts();
   musicPlayer.stopPlaying();
   delay(100);
   interrupts();
   delay(100);
   Player4StepMode();
   
   Player4LCDMode();
   
   Player4StepHome();
   theaterChaseRainbow(50);
   resetVariables(); 
  }
  
  //This assigns a loser in a tie
  else if (finalTimeP1 == finalTimeP2 && finalTimeP1 == finalTimeP3 && finalTimeP1 == finalTimeP4){
   noInterrupts();
   musicPlayer.stopPlaying();
   delay(100);
   interrupts();
   delay(100);
   Player1StepMode();
   
   Player1LCDMode();
  
   Player1StepHome();
   musicPlayer.playFullFile("track006.mp3");
   theaterChaseRainbow(50);
   resetVariables();
  }
}

//Moves shot glass to loser
void Player1StepMode(){
 digitalWrite(en,LOW); //enabled stepper
 digitalWrite(dir,LOW); //pin low to move "forward"

 for(x= 0; x<50; x++)  //Loop the forward stepping
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(300);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(300);
  }
 for(x= 0; x<10550; x++)  //Loop the forward stepping
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(175);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(175);
  }
 for(x= 0; x<50; x++)  //Loop the forward stepping
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(300);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(300);
  }
 delay(750);
  
 for(x= 0; x<50; x++)  
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(300);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(300);
  }
 for(x= 0; x<4000; x++)  
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(175);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(175);
  }
  
 for(x= 0; x<50; x++)  
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(300);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(300);
  }
  delay(750);
 
  digitalWrite(dir,HIGH); //Pull direction pin high to move "reverse"
 for(x= 0; x<50; x++)  //Loop the stepping
  {
    digitalWrite(stp,HIGH); //Trigger one step forward/
    delayMicroseconds(300);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(300);
  }
 for(x= 0; x<12050; x++)  //Loop the stepping
  {
    digitalWrite(stp,HIGH); //Trigger one step forward/
    delayMicroseconds(175);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(175);
  }
 for(x= 0; x<50; x++)  //Loop the stepping
  {
    digitalWrite(stp,HIGH); //Trigger one step forward/
    delayMicroseconds(300);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(300);
  }
  delay(1);
}

//Moves shot glass to loser
void Player2StepMode()
{
  digitalWrite(en,LOW); //enabled stepper
  digitalWrite(dir, LOW); //Pull direction pin low to move "forward"
  
  for(x= 0; x<50; x++)  //Loop the forward stepping
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(300);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(300);
  }
  
  for(x= 0; x<10550; x++)  //Loop the forward stepping
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(175);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(175);
  }
  for(x= 0; x<50; x++)  //Loop the forward stepping
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(300);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(300);
  }
  delay(750);
  
  digitalWrite(dir, HIGH); //Pull direction pin high to move "reverse"

  for(x= 0; x<50; x++)  //Loop the reverse stepping
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(300);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(300);
  }
   for(x= 0; x<3950; x++)  //Loop the reverse stepping
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(175);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(175);
  }
   for(x= 0; x<50; x++)  //Loop the reverse stepping
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(300);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(300);
  }
  delay(1);

}

//Moves shot glass to loser
void Player3StepMode()
{
  digitalWrite(en,LOW); //enabled
  digitalWrite(dir, LOW); //Pull direction pin low to move "forward"

  for(x= 0; x<50; x++)  //Loop the forward stepping
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(300);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(300);
  }
  for(x= 0; x<10550; x++)  //Loop the forward stepping
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(175);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(175);
  }
  for(x= 0; x<50; x++)  //Loop the forward stepping
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(300);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(300);
  }
  
  
  delay(750);
  
  digitalWrite(dir,LOW); //Pull direction pin low to move "forward"
 
  for(x= 0; x<50; x++)  //Loop the reverse stepping
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(300);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(300);
  }
  for(x= 0; x<4000; x++)  //Loop the reverse stepping
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(175);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(175);
  }
  for(x= 0; x<50; x++)  //Loop the reverse stepping
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(300);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(300);
  }
  
  delay(750);
  
  digitalWrite(dir, HIGH); //Pull direction pin high to move "reverse"

  for(x= 0; x<50; x++)  //Loop the forward stepping
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(300);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(300);
  }
  for(x= 0; x<4000; x++)  //Loop the forward stepping
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(175);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(175);
  }
  for(x= 0; x<50; x++)  //Loop the forward stepping
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(300);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(300);
  }
  
  delay(1);
}

//Moves shot glass to loser
void Player4StepMode()
{
  digitalWrite(en,LOW); //enabled
  digitalWrite(dir, LOW); //Pull direction pin low to move "forward"

  for(x= 0; x<50; x++)  //Loop the forward stepping
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(300);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(300);
  }
  for(x= 0; x<6500; x++)  //Loop the forward stepping
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(175);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(175);
  }
  for(x= 0; x<50; x++)  //Loop the forward stepping
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(300);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(300);
  }
  
  
  delay(750);
  
  digitalWrite(dir, LOW); //forward
 
  for(x= 0; x<50; x++)  //Loop the forward stepping
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(300);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(300);
  }
   for(x= 0; x<3950; x++)  //Loop the forward stepping
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(175);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(175);
  }
   for(x= 0; x<50; x++)  //Loop the forward stepping
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(300);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(300);
  }
  
  delay(750);
  
  digitalWrite(dir, LOW); //Pull direction pin low to move "forward"

  for(x= 0; x<50; x++)  //loop
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(300);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(300);
  }
  for(x= 0; x<4000; x++)  //loop
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(175);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(175);
  }
  for(x= 0; x<50; x++)  //loop
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(300);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(300);
  }
  
  delay(1);
}

//LCD & Neopixel function for loser
void Player1LCDMode(){//RED BUTTON
  if (! musicPlayer.startPlayingFile("/loser001.mp3")) {
  while (1);
  }

  while (musicPlayer.playingMusic) {
 
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("RED PLAYER");
  lcd.setBacklight(RED);
  lcd.setCursor(0,1);
  lcd.print("DRINK UP");
  
  theaterChase(strip.Color(255,   0,   0), 50); // Red, half brightness
  colorWipe(strip.Color(255,   0,   0), 20); // Red
  colorWipe(strip.Color(  0,   0,   0), 20); // off
  theaterChase(strip.Color(255,   0,   0), 50); // Red, half brightness
  colorWipe(strip.Color(255,   0,   0), 20); // Red
  colorWipe(strip.Color(  0,   0,   0), 20); // off
  theaterChase(strip.Color(255,   0,   0), 50); // Red, half brightness
  colorWipe(strip.Color(  0,   0,   0), 0); //off // Turn off the game LED
  strip.show();
  }
  musicPlayer.softReset();
  delay(500);
  lcd.clear(); //clears previous data in display
  lcd.print(" DRINKING GAME");
  lcd.setCursor(0,1); //set invisible cursor to the first column (column 0), second line (line 1)
  lcd.print(" FOR THE BRAVE");
  lcd.setBacklight(WHITE);
  delay(1000);
}

//LCD & Neopixel function for loser
void Player2LCDMode(){//BLUE BUTTON

  if (! musicPlayer.startPlayingFile("/loser004.mp3")) {
  while (1);
  }

  while (musicPlayer.playingMusic) {

  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("BLUE PLAYER");
  lcd.setBacklight(BLUE);
  lcd.setCursor(0,1);
  lcd.print("SHOOT IT!");
  
  theaterChase(strip.Color(0,0,255), 50); // blue, half brightness
  colorWipe(strip.Color(0,0,255), 20); // blue
  colorWipe(strip.Color(  0,   0,   0), 20); // off
  theaterChase(strip.Color(0,0,255), 50); // blue, half brightness
  colorWipe(strip.Color(0,0,255), 20); // blue
  colorWipe(strip.Color(  0,   0,   0), 20); // off
  theaterChase(strip.Color(0,0,255), 50); // blue, half brightness
  colorWipe(strip.Color(  0,   0,   0), 0); //off // Turn off the game LED
  strip.show();
  }
  musicPlayer.softReset();
  delay(500);
  lcd.clear(); //clears previous data in display
  lcd.print(" DRINKING GAME");
  lcd.setCursor(0,1); //set invisible cursor to the first column (column 0), second line (line 1)
  lcd.print(" FOR THE BRAVE");
  lcd.setBacklight(WHITE);
  delay(1000);
}

//LCD & Neopixel function for loser
void Player3LCDMode(){//GREEN BUTTON
 
  if (! musicPlayer.startPlayingFile("/loser002.mp3")) {
  while (1);
  }

  while (musicPlayer.playingMusic) {
 
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("GREEN PLAYER");
  lcd.setBacklight(GREEN);
  lcd.setCursor(0,1);
  lcd.print("DRINK UP");
  
  theaterChase(strip.Color(0,128,0), 50); // green, half brightness
  colorWipe(strip.Color(0,128,0), 20); // green
  colorWipe(strip.Color(  0,   0,   0), 20); // off
  theaterChase(strip.Color(0,128,0), 50); // green, half brightness
  colorWipe(strip.Color(0,128,0), 20); // green
  colorWipe(strip.Color(  0,   0,   0), 20); // off
  theaterChase(strip.Color(0,128,0), 50); // green, half brightness
  colorWipe(strip.Color(  0,   0,   0), 0); //off // Turn off the game LED
  strip.show();
  }
  musicPlayer.softReset();
  delay(500);
  lcd.clear(); //clears previous data in display
  lcd.print(" DRINKING GAME");
  lcd.setCursor(0,1); //set invisible cursor to the first column (column 0), second line (line 1)
  lcd.print(" FOR THE BRAVE");
  lcd.setBacklight(WHITE);
  delay(1000);
}

//LCD & Neopixel function for loser
void Player4LCDMode(){//YELLOW BUTTON

  if (! musicPlayer.startPlayingFile("/loser003.mp3")) {
  while (1);
  }

  while (musicPlayer.playingMusic) {

  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("YELLOW PLAYER");
  lcd.setBacklight(YELLOW);
  lcd.setCursor(0,1);
  lcd.print("SHOOT IT!");
  
  theaterChase(strip.Color(255,255,0), 50); // yellow, half brightness
  colorWipe(strip.Color(255,255,0), 20); // yellow
  colorWipe(strip.Color(  0,   0,   0), 20); // off
  theaterChase(strip.Color(255,255,0), 50); // yellow, half brightness
  colorWipe(strip.Color(255,255,0), 20); // yellow
  colorWipe(strip.Color(  0,   0,   0), 20); // off
  theaterChase(strip.Color(255,255,0), 50); // yellow, half brightness
  colorWipe(strip.Color(  0,   0,   0), 0); //off // Turn off the game LED
  strip.show();
  }
  musicPlayer.softReset();
  delay(500);
  lcd.clear(); //clears previous data in display
  lcd.print(" DRINKING GAME");
  lcd.setCursor(0,1); //set invisible cursor to the first column (column 0), second line (line 1)
  lcd.print(" FOR THE BRAVE");
  lcd.setBacklight(WHITE);
  delay(1000);
}

//Moves shot glass back to home position
void Player1StepHome()
{
  //Red Player Stepping 
  digitalWrite(dir, HIGH); //Pull direction pin high to move "reverse"

  for(x= 0; x<2600; x++)  //Loop the forward stepping
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(300);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(300);
  }
}

//Moves shot glass back to home position
void Player2StepHome()
{
  //Blue Player Stepping 
  digitalWrite(dir, HIGH); //Pull direction pin high to move "reverse"
  
  for(x= 0; x<6600; x++)  //Loop the forward stepping
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(300);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(300);
  }
}

//Moves shot glass back to home position
void Player3StepHome()
{
  //Green Player Stepping 
  digitalWrite(dir, HIGH); //Pull direction pin high to move "reverse"
 
  for(x= 0; x<10650; x++)  //Loop the forward stepping
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(300);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(300);
  }
}

//Moves shot glass back to home position
void Player4StepHome()
{
  //Yellow Player Stepping 
  digitalWrite(dir, HIGH); //Pull direction pin high to move "reverse"
 
  for(x= 0; x<14750; x++)  //Loop the forward stepping
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delayMicroseconds(300);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delayMicroseconds(300);
  }
}

//Neopixel effect
void colorWipe(uint32_t color, int wait) {
  for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
    strip.setPixelColor(i, color);         //  Set pixel's color (in RAM)
    strip.show();                          //  Update strip to match
    delay(wait);                           //  Pause for a moment
  }
}

//Neopixel effect
void rainbow(int wait) {

  for(long firstPixelHue = 0; firstPixelHue < 1*65536; firstPixelHue += 256) {
    for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...

      int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
     
      strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
    }
    strip.show(); // Update strip with new contents
    delay(wait);  // Pause for a moment
  }
}

//Neopixel effect
void theaterChase(uint32_t color, int wait) {
  for(int a=0; a<20; a++) {  // Repeat 10 times...
    for(int b=0; b<3; b++) { //  'b' counts from 0 to 2...
      strip.clear();         //   Set all pixels in RAM to 0 (off)
      
      for(int c=b; c<strip.numPixels(); c += 3) {
        strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
      }
      strip.show(); // Update strip with new contents
      delay(wait);  // Pause for a moment
    }
  }
}

//Neopixel effect
void theaterChaseRainbow(int wait) {
  int firstPixelHue = 0;     // First pixel starts at red (hue 0)
  for(int a=0; a<15; a++) {  // Repeat 30 times...
    for(int b=0; b<3; b++) { //  'b' counts from 0 to 2...
      strip.clear();         //   Set all pixels in RAM to 0 (off)
    
      for(int c=b; c<strip.numPixels(); c += 3) {
      
        int      hue   = firstPixelHue + c * 65536L / strip.numPixels();
        uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB
        strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
      }
      strip.show();                // Update strip with new contents
      delay(wait);                 // Pause for a moment
      firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
    }
  }
}

//SD Card on musicmaker shield
void printDirectory(File dir, int numTabs) {
   while(true) {
     
     File entry =  dir.openNextFile();
     if (! entry) {
       // no more files
       //Serial.println("**nomorefiles**");
       break;
     }
     for (uint8_t i=0; i<numTabs; i++) {
       Serial.print('\t');
     }
     Serial.print(entry.name());
     if (entry.isDirectory()) {
       Serial.println("/");
       printDirectory(entry, numTabs+1);
     } else {
       // files have sizes, directories do not
       Serial.print("\t\t");
       Serial.println(entry.size(), DEC);
     }
     entry.close();
   }
}

//Resets back to initial state
void resetVariables(){
  digitalWrite(en,HIGH);//disabled
  musicPlayer.softReset();
  strip.clear();
  strip.show();
  buttonStateP1 = 0;
  buttonStateP2 = 0;
  buttonStateP3 = 0;
  buttonStateP4 = 0;
  lastButtonStateP1 = 0; 
  lastButtonStateP2 = 0;
  lastButtonStateP3 = 0; 
  lastButtonStateP4 = 0;
  startButtonState = HIGH;
  buttonStateP1 = HIGH;
  buttonStateP2 = HIGH;
  buttonStateP3 = HIGH;
  buttonStateP4 = HIGH;
  allDone = false;
  gameOn = false;
  p1Done = false;
  p2Done = false;
  p3Done = false;
  p4Done = false;
  randomTime = 0;
  startTime = 0;
  p1Done = false;
  p2Done = false;
  p3Done = false;
  p4Done = false;
  finalTimeP1 = 0;
  finalTimeP2 = 0;
  finalTimeP3 = 0;
  finalTimeP4 = 0;
}

Schematics

Drinking Game
drinkinggame_nTguNCoj6O.fzz

Comments

Author

Default
jdmgolf123
  • 1 project
  • 2 followers

Additional contributors

Published on

September 29, 2019

Members who respect this project

DefaultDefaultDefault974490 ic83bpyyzzDefaultDefaultDefaultProfilepic

and 7 others

See similar projects
you might like

Similar projects you might like

Arduino Pocket Game Console + A-Maze - Maze Game

Project tutorial by Alojz Jakob

  • 9,271 views
  • 8 comments
  • 25 respects

Arduino Dot Matrix Game Console

Project tutorial by Md. Khairul Alam

  • 11,174 views
  • 1 comment
  • 34 respects

Ninja Dollar - LCD game

Project tutorial by anime

  • 4,694 views
  • 7 comments
  • 7 respects

Make an Arduino Memory Game

Project tutorial by Jeremie

  • 17,474 views
  • 38 comments
  • 42 respects

Existential Crisis - Arduino Role-Playing Game Simulator

Project showcase by Cory Potter

  • 1,016 views
  • 0 comments
  • 4 respects

Arduino Game By LCD

Project tutorial by Mohammed Magdy

  • 53,087 views
  • 52 comments
  • 169 respects
Add projectSign up / Login