Use a for loop to sweep the buzzer's tone smoothly up and back down. Extension activity — for loops are beyond the core unit.
From the unit Crack the Code
· activity PRP 4: Digital output — Buzzer
int i = 200;
const int ALARMSOUNDER = 3; // the buzzer is on pin D3
void setup() {
pinMode(ALARMSOUNDER, OUTPUT);
}
void loop() {
for (i = 200; i < 700; i = i + 2) { // sweep from a low tone up to a high tone
tone(ALARMSOUNDER, i, 10); // play the tone, changing every 10 ms
delay(10);
}
for (i = 701; i > 200; i = i - 2) { // sweep back down
tone(ALARMSOUNDER, i, 10);
delay(10);
}
}
Shared from Little Bird Electronics curriculum.