Pinball Wizard Code (Arduino)

This is just a snippet of our Arduino code that we wanted to highlight. It's the while loop that runs our code.

void loop() {
// put your main code here, to run repeatedly:
sensorValue1 = analogRead(interruptPin1);
sensorValue2 = analogRead(interruptPin2);
if (sensorValue1 > 200 && !scored) {
addScore();
scoreTime = 2000;
scored = true;
}
if (sensorValue2 > 200 && !loss) {
loseBall();
lossTime = 2000;
loss = true;
}
count--;
if (count == 0) {
count = goalie(on);
}
scoreTime--;
if (scoreTime == 0) {
digitalWrite(buzzer, LOW);
scored = false;
}
lossTime--;
if (lossTime == 0) {
loss = false;
}
}</code>

<code>


The interesting thing about this while loop is that since all the meat of the code is in functions that toggle certain pins high and low after a certain number of loops we do not have to worry as much about interrupts. We came up with this idea because the Arduino Uno only had two interrupt ports when we needed at least three to make our project run. Our functions were used to activate motors, and light LEDs quickly so that the loop could run faster allowing it to detect the sensors extremely quickly.

Pinball Wizard Schematic

WP_20160428_004

LED: We set one of the pins on the Arduino HIGH which outputs to a circuit which is an LED in line with a resistor to limit current.

Motor: We set up an NPN transistor as a relay. In this configuration we have power supplied to the motor and the path to ground is controlled by the transistor. Setting the port high allows the transistor to connect the motor to GND.

Buzzer: Set up in the same fashion as the motor.

Pressure Sensor: The pressure sensor acted like a potentiometer. While the sensor was not pressed it had so much resistance that it acted like an open circuit. When the sensor was pressed is lowered the resistance and acted like a short circuit which made the voltage on the port readable.

Pinball Wizard: Big Picture

WP_20160428_002

The goal of this project was to work together to create a pinball game. We chose a pinball machine because of the challenge and fun reward we would receive learning how to program and put one together. There were a few steps that had to be taken in order to meet this goal. First was to design the board and plan out what parts we needed. The theme of the board is a soccer themed pinball machine. So we needed two motors to act as the “goalie”. We also needed two pressure sensors in order to sense if a goal was made or a life was lost. Of course we needed wood, to build the board out of. Lastly we needed the parts that everyone recognizes from a pinball machine, the small silver ball, the plunger to shoot the ball into the playing field, the flippers that the player controls, and the score board. Once designed and all the pieces gathered, the next step was to build the board and program all the parts together. We did these steps simultaneously, with all of us bouncing back and forth (I see exactly what you did there-CKH) between helping build the board and working on getting all the motors and sensors working outside the board. Finally we were close enough finished with both of those steps that we put all the parts in the board and put the finishing touches on it.