#define buzzer D8
#define potX D2
int notes[] = {262, 294, 330, 349, 392, 440, 494, 523};
int numNotes = 8;
void setup() {
ledcAttach(buzzer, 2000, 10); // canal PWM para sonido
}
void loop() {
int value = analogRead(potX);
int index = map(value, 0, 4095, 0, numNotes - 1);
int freq = notes[index];
ledcWriteTone(buzzer, freq);
delay(50);
}Loading
xiao-esp32-c3
xiao-esp32-c3