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) {
scoreTime = 2000;
scored = true;
if (sensorValue2 > 200 && !loss) {
lossTime = 2000;
loss = true;
if (count == 0) {
count = goalie(on);
if (scoreTime == 0) {
digitalWrite(buzzer, LOW);
scored = false;
if (lossTime == 0) {
loss = false;


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.