BUG HUNT 1: FOUR NOTE PIANO WITH SYNCED LED
Step 2 - Look For Errors // TROUBLESHOOT

/* * Play a tone on a speaker attached to pin A5 and light an LED on * pin 2 when buttons attached to pins 4,6,9,12 are pressed. */ void setup() { pinMode(A5, OUTPUT); //speaker //initialize the buttons as inputs: pinMode(4,INPUT_PULLUP); pinMode(6,INPUT); pinMode(9,INPUT); pinMode(12,INPUT_PULLUP); } void loop() { //if a button is pressed, play the tone (in hertz) and light up the LED. if (digitalRead(4) == LOW) { tone(250, A5); digitalWrite(2, HIGH); } else if (digitalRead(6) == LOW) { tone(A5, 350); digitalWrite(2, HIGH); } else if (digitalRead(9) == LOW) { tone(A5, 450); digitalWrite(2, HIGH); } else if (digitalRead(12) == LOW) { tone(A5, 550); digitalWrite(2, HIGH); } else { digitalWrite(2, LOW); } } // (c) 2017 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 

Looking for answers?  Click Next Step below to see them.