(Derek Heath & Garret Verstegen) Arduino + Pachinko = This

Pachinko

In an attempt to use both gravity and light to create a simple playing field game, Garret and I decided to take a simple game format (Pachinko) and test our skills at building and programming by making a light sensitive Pachinko game. To play, the ball is dropped in the top of the board by Player 1, and before it reaches the bottom, Player 2 must decide which of the 3 sensors it will land on and lock in their choice with the respective button. If the ball does in fact land on the predicted sensor, both lights by that sensor will be lit and a buzzer confirms a point scored. The players then switch roles.

Here’s the code!:

//     PACHINKO MADNESS
//
//     GARRET VERSTEGEN
//     DEREK HEATH
//
//     DESMA 157A - GAMING I
//
//     PROF: EDDO STERN
//     TA: DAVID ELLIOTT
//
//     THIS ONE GOES OUT TO ALL THE PRETTY GIRLS IN THE WORLD.
//     AND THE ALL THE UGLY GIRLS TOO.
//     CAUSE TO ME YOU’RE PRETTY ANYWAY.
//
//     LETS GET IT.

#define LPC  1  // the ANALOG pin for LEFT photocell
#define TLLED  3  // the pin for TOP-LEFT led
#define BLLED  4  // the pin for BOTTOM-LEFT led
#define LB 9 // the LEFT input pin where the pushbutton is connected

#define CPC  3  // the ANALOG pin for CENTER photocell
#define TCLED  5  // the pin for TOP-CENTER led
#define BCLED  6  // the pin for BOTTOM-CENTER led
#define CB 10 // the CENTER input pin where the pushbutton is connected

#define RPC  5  // the ANALOG pin for RIGHT photocell
#define TRLED  7  // the pin for TOP-RIGHT led
#define BRLED  8  // the pin for BOTTOM-RIGHT led
#define RB 11 // the RIGHT input pin where the pushbutton is connected

#define BUZZ 12 // the pin for the BUZZER

int LBVAL = 0;     // val will be used to store the state of the LEFT-BUTTON input pin
int CBVAL = 0;     // val will be used to store the state of the CENTER-BUTTON input pin
int RBVAL = 0;     // val will be used to store the state of the RIGHT-BUTTON input pin

int LPCVAL = 0;     // val will be used to store the state of the LEFT-PHOTOCELL input pin
int CPCVAL = 0;     // val will be used to store the state of the CENTER-PHOTOCELL input pin
int RPCVAL = 0;     // val will be used to store the state of the RIGHT-PHOTOCELL input pin

int LGUESS = 0;
int CGUESS = 0;
int RGUESS = 0;

int LANSW = 0;
int CANSW = 0;
int RANSW = 0;

void setup() {
pinMode(TLLED, OUTPUT);
pinMode(BLLED, OUTPUT);
pinMode(LB, INPUT);

pinMode(TCLED, OUTPUT);
pinMode(BCLED, OUTPUT);
pinMode(CB, INPUT);

pinMode(TRLED, OUTPUT);
pinMode(BRLED, OUTPUT);
pinMode(RB, INPUT);

pinMode(BUZZ, OUTPUT);

digitalWrite(TLLED, LOW);
digitalWrite(BLLED, LOW);
digitalWrite(TCLED, LOW);
digitalWrite(BCLED, LOW);
digitalWrite(TRLED, LOW);
digitalWrite(BRLED, LOW);
digitalWrite(BUZZ, LOW);
Serial.begin(9600);
}

void loop() {
// SET PC LED OFF
digitalWrite(TLLED, LOW);
digitalWrite(TCLED, LOW);
digitalWrite(TRLED, LOW);
// READ/SET DEM BUTTONS
CBVAL = digitalRead(CB); // read input value and store it
LBVAL = digitalRead(LB); // read input value and store it
RBVAL = digitalRead(RB); // read input value and store it
LPCVAL = analogRead(LPC); // read input value and store it
CPCVAL = analogRead(CPC); // read input value and store it
RPCVAL = analogRead(RPC); // read input value and store it

if (LBVAL == HIGH){
digitalWrite(BRLED, LOW);
digitalWrite(BCLED, LOW);
digitalWrite(BLLED, HIGH);
RGUESS = 0;
CGUESS = 0;
LGUESS = 1;
delay(100);
}
else if (CBVAL == HIGH){
digitalWrite(BRLED, LOW);
digitalWrite(BCLED, HIGH);
digitalWrite(BLLED, LOW);
RGUESS = 0;
CGUESS = 1;
LGUESS = 0;
delay(100);
}
else if (RBVAL == HIGH){
digitalWrite(BRLED, HIGH);
digitalWrite(BCLED, LOW);
digitalWrite(BLLED, LOW);
RGUESS = 1;
CGUESS = 0;
LGUESS = 0;
delay(100);
}
//
// SET DEM LIGHTS
if (LPCVAL < 1 || CPCVAL < 1 || RPCVAL < 1){
if (LPCVAL < 1){
digitalWrite(TLLED, HIGH);
digitalWrite(TCLED, LOW);
digitalWrite(TRLED, LOW);
LANSW = 1;
CANSW = 0;
RANSW = 0;
}
else if (CPCVAL < 2){
digitalWrite(TLLED, LOW);
digitalWrite(TCLED, HIGH);
digitalWrite(TRLED, LOW);
LANSW = 0;
CANSW = 1;
RANSW = 0;
}
else if (RPCVAL < 1){
digitalWrite(TLLED, LOW);
digitalWrite(TCLED, LOW);
digitalWrite(TRLED, HIGH);
LANSW = 0;
CANSW = 0;
RANSW = 1;
}
}
// SEE IF YOU WIN OR LOSE
if (LPCVAL < 1 || CPCVAL < 1 || RPCVAL < 1 && LGUESS == LANSW){
digitalWrite(BUZZ, HIGH);
delay(1000);
digitalWrite(BUZZ, LOW);
digitalWrite(TLLED, LOW);
digitalWrite(BLLED, LOW);
LGUESS = 0;
LANSW = 0;
}
if (LPCVAL < 1 || CPCVAL < 1 || RPCVAL < 1 && CGUESS == CANSW){
digitalWrite(BUZZ, HIGH);
delay(1000);
digitalWrite(BUZZ, LOW);
digitalWrite(TCLED, LOW);
digitalWrite(BCLED, LOW);
CGUESS = 0;
CANSW = 0;
}
if (LPCVAL < 1 || CPCVAL < 1 || RPCVAL < 1 && RGUESS == RANSW){
digitalWrite(BUZZ, HIGH);
delay(1000);
digitalWrite(BUZZ, LOW);
digitalWrite(TRLED, LOW);
digitalWrite(BRLED, LOW);
RGUESS = 0;
RANSW = 0;
}
}