(Derek Heath & Garret Verstegen) Quick Stick 2.0

Quick Stick 2

For Quick Stick round two, Garret and I decided to really take advantage of the fact that we had electronics and the fabulous laser cutter at our disposal. We also wanted to expand upon what we thought was a fun, original basis for further game design. This version of Quick Stick is almost entirely mechanical. Gameplay and rules are as follows:

- One player is designated pitcher and the other batter at the start of the game. They each hold the respective controllers attached to the baseball diamond board.

- The “Quick Stick” itself is placed so that it rests on top of a resting pull solenoid in the drop slot

- To pitch the ball, the pitcher calls out either “fastball” or “curveball” and then presses the respective button on his controller which pulls back the solenoid and drops the stick down a chute.

- The stick is divided into sections: a section for curveball which has areas designated for (largest to smallest) a single base hit, double, or triple. An out section exists above this, and above that a fastball section operates by the same divisions the curveball section does. At the very top is a small section for “home run.”

- The batter must press his button to “bat” when the area called out is in front of the solenoid. This releases the solenoid down and stops the stick.

- However many bases the batter scores is determined by which area of the stick he hits. If he fails to hit the designated area he recieves an “out.”

- All this data is sent to the diamond board by a mechanism we’ve devised–3 LEDs are placed behind the stick dropping chute and shine through holes in the stick itself once it is stopped and resting on the solenoid in any given area. On the other side of the stick, 3 photocells read the LEDs that are visible (via the different placement of holes on the stick) and sends this “code” to the gameboard.

- Once the code is on the gameboard, it operates much like normal baseball. Lights light up in the bases to indicate when men are on base, outs light when a player gets out, etc. Lights flash when a player makes it home and scores are then tabulated by hand on the board with a dry erase marker.

- Game can last for 9 innings or less, and winner is determined by whoever has scored more runs.

Heres the code:

//digitalpins
int bat = 2;
int homebase = 3;
int firstbase = 4;
int secondbase = 5;
int thirdbase = 6;
int strikeone = 7;
int striketwo = 8;
int strikethree = 9;
int buzzer = 1;
int curveballbutton = 13;
int fastballbutton = 12;
int hitbutton = 10;
int resetbutton = 11;

// binary variables
byte controla;
byte controlb;
byte swing;
byte scored;
byte reset;

// integer variables
int strikes; // amount of strikes
int pitchtype;// to match with hitttype for strikes
int hittype;  // to match with pitchtype for strikes
int shift; // amount of bitshifting
int PA;       // photocell 1
int PB;       // photocell 2
int PC;       // photocell 3
int threshold;

//byte variables
byte bases = B00000001;

// # defines
#define fastball 1
#define curveball 2
#define homerun 3
#define strike 4

void setup(){
//outputs
pinMode(bat, OUTPUT);
pinMode(homebase, OUTPUT);
pinMode(firstbase, OUTPUT);
pinMode(secondbase, OUTPUT);
pinMode(thirdbase, OUTPUT);
pinMode(strikeone, OUTPUT);
pinMode(striketwo, OUTPUT);
pinMode(strikethree, OUTPUT);
pinMode(buzzer, OUTPUT);

//inputs
pinMode(curveballbutton, INPUT);
pinMode(fastballbutton, INPUT);
pinMode(hitbutton, INPUT);
pinMode(resetbutton, INPUT);

//writes
digitalWrite(homebase, LOW);
digitalWrite(firstbase, LOW);
digitalWrite(secondbase, LOW);
digitalWrite(thirdbase, LOW);
digitalWrite(strikeone, LOW);
digitalWrite(striketwo, LOW);
digitalWrite(strikethree, LOW);
digitalWrite(buzzer, LOW);
digitalWrite(bat, LOW);

//init vars
int controla = 1;
int controlb = 0;
int swing = 0;
int scored = 0;
int reset = 0;

// integer variables
int strikes = 0; // amount of strikes
int threshold = 1;
}

void loop(){

if (controla == 1 && swing == 0 && digitalRead(curveballbutton) == HIGH){
pitchtype = curveball;
controla = 0;
controlb = 1;
digitalWrite(bat, HIGH);
}
else if (controla == 1 && swing == 0 && digitalRead(fastballbutton) == HIGH){
pitchtype = fastball;
controla = 0;
controlb = 1;
digitalWrite(bat, HIGH);
}

if (controlb == 1 && swing == 0 && digitalRead(hitbutton) == HIGH){
controlb = 0;
controla = 1;
digitalWrite(bat, LOW);
digitalWrite(homebase, LOW);
swing = 1;
delay(2000);
PA = analogRead(0);
PB = analogRead(1);
PC = analogRead(2);
}

if (swing == 1){
if(PA > threshold && PB <= threshold && PC > threshold){
hittype = homerun;
shift = 4;
}
if(PA <= threshold && PB > threshold && PC <= threshold){
hittype = fastball;
shift = 3;
}
if(PA <= threshold && PB <= threshold && PC > threshold){
hittype = fastball;
shift = 2;
}
if(PA <= threshold && PB <= threshold && PC <= threshold){
hittype = fastball;
shift = 1;
}
if(PA <= threshold && PB <= threshold && PC <= threshold){
hittype = curveball;
shift = 3;
}
if(PA > threshold && PB <= threshold && PC <= threshold){
hittype = curveball;
shift = 2;
}
if(PA > threshold && PB > threshold && PC <= threshold){
hittype = curveball;
shift = 1;
}
if(PA > threshold && PB > threshold && PC > threshold){
hittype = strike;
shift = 0;
}
scored = 1;
}

if (scored == 1){
if (hittype == pitchtype){
bases << shift;
runthebases(bases);
buzzthebases(bases);
}
if (hittype == homerun){
bases << shift;
runthebases(bases);
buzzthebases(bases);
}
if (hittype == strike){
strikes++;
strikethebases(strikes);
}
else {
strikes++;
strikethebases(strikes);
}
reset = 1;
scored = 0;
swing = 0;
}

if (reset == 1 && swing == 1 && digitalRead(resetbutton) == HIGH){
digitalWrite(bat, HIGH);
swing = 0;
delay(5000);
digitalWrite(bat, LOW);
digitalWrite(homebase, HIGH);
bitSet(bases, 0);
reset = 0;
}
}

void runthebases(byte bases){
if (bitRead(bases, 1) == 1){
digitalWrite(firstbase, HIGH);
}
else {
digitalWrite(firstbase, LOW);
}
if (bitRead(bases, 2) == 1){
digitalWrite(secondbase, HIGH);
}
else {
digitalWrite(secondbase, LOW);
}
if (bitRead(bases, 3) == 1){
digitalWrite(thirdbase, HIGH);
}
else {
digitalWrite(thirdbase, LOW);
}
}

void buzzthebases(byte bases){
if (bitRead(bases, 4) == 1){
digitalWrite(buzzer, HIGH);
delay(1000);
digitalWrite(buzzer, LOW);
bitClear(bases, 4);
}
if (bitRead(bases, 5) == 1){
digitalWrite(buzzer, HIGH);
delay(1000);
digitalWrite(buzzer, LOW);
bitClear(bases, 5);
}
if (bitRead(bases, 6) == 1){
digitalWrite(buzzer, HIGH);
delay(1000);
digitalWrite(buzzer, LOW);
bitClear(bases, 6);
}
if (bitRead(bases, 7) == 1){
digitalWrite(buzzer, HIGH);
delay(1000);
digitalWrite(buzzer, LOW);
bitClear(bases, 7);
}
}

void strikethebases(int strikes){
switch (strikes){
case 1:
digitalWrite(strikeone, HIGH);
digitalWrite(striketwo, LOW);
digitalWrite(strikethree, LOW);
break;
case 2:
digitalWrite(strikeone, HIGH);
digitalWrite(striketwo, HIGH);
digitalWrite(strikethree, LOW);
break;
case 3:
digitalWrite(buzzer, HIGH);
digitalWrite(strikeone, HIGH);
digitalWrite(striketwo, HIGH);
digitalWrite(strikethree, HIGH);
delay(3000);
digitalWrite(buzzer, LOW);
digitalWrite(strikeone, LOW);
digitalWrite(striketwo, LOW);
digitalWrite(strikethree, LOW);
strikes = 0;
break;
}
}