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.