//Access: https://wokwi.com/projects/359792790748967937
int potPin = A0; // potentiometer pin
int buzzerPin = 13; // buzzer pin
int volume = 0; // initial volume level
void setup() {
pinMode(buzzerPin, OUTPUT);
}
void loop() {
volume = analogRead(potPin);
volume = map(volume, 0, 1023, 0, 3);
switch (volume) {
// turn off the buzzer
case 0:
noTone(buzzerPin);
break;
// play a low tone for 50 ms
case 1:
tone(buzzerPin, 500, 50);
break;
// play a medium tone for 250 ms
case 2:
tone(buzzerPin, 1000, 250);
break;
// play a high tone for 500 ms
case 3:
tone(buzzerPin, 2000, 500);
break;
}
delay(10);
}