Copy the code within the green box, then paste it into the code window below.

Click to Show or Hide the code.

/*
* Play a tone on a speaker attached to pin A5 when
* buttons attached to pins 4,6,9,12 are pressed.
*/


void setup(){
pinMode(A5, OUTPUT); //speaker pin

//initialize the buttons as inputs:
pinMode(4,INPUT_PULLUP);
pinMode(6,INPUT_PULLUP);
pinMode(9,INPUT_PULLUP);
pinMode(12,INPUT_PULLUP);
}

void loop(){
//if a button is pressed, play the corresponding tone (in hertz)
if (digitalRead(4) == LOW) {
tone(A5,250);
}
else if (digitalRead(6) == LOW) {
tone(A5,350);
}
else if (digitalRead(9) == LOW) {
tone(A5,450);
}
else if (digitalRead(12) == LOW) {
tone(A5,550);
}

else{ noTone(A5);
}
}

// Replace the tone value 250 with a variable you create. Then make each
// higher note have a tone of: yourToneVariable + a number

// Need help? http://www.letsstartcoding.com/help

// (c) 2016 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense

Paste the code from above into the coding window below using Control + V. Right-click and paste will not work.