Speaker Variable Tone Bug Hunt! Test your Troubleshooting.
//Use a variable to increase the pitch on Speaker every time the loop runs
void setup(){
pinMode(10,OUTPUT); //set the speaker as an OUTPUT
}
void loop(){
int pitch = 40; //create an integer variable named 'pitch'. Start its value at 40
tone(10,pitch); //Play 'pitch' on the speaker. On the first loop, it will equal 40
delay(3); //delay 3 milliseconds with a pitch playing
pitch = pitch + 10 ; //increase pitch variable by 10 before restarting the loop
}
// (c) 2018 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
Heads up! You need our Chrome App to run this code.
Success!
Compile errors:
Serial port monitor:
Input:
Need a hint? Click here.
Where you create a variable matters in code. If you create a variable inside the void loop, that variable will get reset to its starting value every time the loop runs.
In this program, that means your variable is getting set to 40 each time the loop runs, so it can't rise like it's supposed to. Check out the project page to remember where the variable should be created.