int state = 0; Variable to hold the current state. int pressed; Indicates which button was pressed. int Photosensor = 0; IO pin number for first button. int Snapbutton = 2; IO pin number for second button. int Pushbutton = 4; IO pin number for third button. int potval1; Holds the value of the first button. int potval2; Holds the value of the second button. int potval3; Holds the value of the third button. int testLEDPin = 13; void setup() { pinMode(testLEDPin, OUTPUT); pinMode(Photosensor, INPUT); pinMode(Photosensor, HIGH); pinMode(Snapbutton, INPUT); Setup these pins as INPUT signals. pinMode(Snapbutton, LOW) pinMode(Pushbutton, INPUT); pinMode(Pushbutton, LOW); Serial.begin(9600); } void loop() { pressed = getButton(); Calls the method that determines which button was pressed. updateState(); Calls the method that changes the state based on the input. } getButton() method waits for a button to be pressed, determines which button was pressed and then returns the button number to the main loop. int getButton() { val1 = LOW; val2 = LOW; Initialize all button values to LOW. val3 = LOW; This while loop waits for a button to be pressed. while ((val1 val2 val3)==LOW) { Conditions is that all three vals must be LOW. As soon as one of them is HIGH, the program exits the loop. BTW HIGH is the same as TRUE; LOW is the same as FALSE. Serial.print(^ ); Print a ^ while waiting for a button to be pressed (button is ^ up). val1 = digitalRead(b1); val2 = digitalRead(b2); Get the values of the buttons. val3 = digitalRead(b3); } These if conditions determine which button was pressed to come out of the while wait bit above. if (val1 == HIGH) pressed = b1; if (val2 == HIGH) pressed = b2; if (val3 == HIGH) pressed = b3; Serial.print(pressed ); Serial.print(pressed); digitalWrite(testLEDPin, HIGH); This while loop waits to be sure that the button was released. while (digitalRead(pressed)==HIGH) { Condition is that digitalRead(pressed) is TRUE. Serial.print(_ ); Print a _ while button is still pressed. } digitalWrite(testLEDPin, LOW); return pressed; } void updateState() { }