// define Buzzer GPIO
const int TONE_OUTPUT_PIN = 26;
const int TONE_PWM_CHANNEL = 0;
void setup() {
ledcAttachPin(TONE_OUTPUT_PIN, TONE_PWM_CHANNEL);
}
void loop() {
// Plays the middle C scale
ledcWriteNote(TONE_PWM_CHANNEL, NOTE_C, 4);
delay(500);
ledcWriteNote(TONE_PWM_CHANNEL, NOTE_D, 4);
delay(500);
ledcWriteNote(TONE_PWM_CHANNEL, NOTE_E, 4);
delay(500);
ledcWriteNote(TONE_PWM_CHANNEL, NOTE_F, 4);
delay(500);
ledcWriteNote(TONE_PWM_CHANNEL, NOTE_G, 4);
delay(500);
ledcWriteNote(TONE_PWM_CHANNEL, NOTE_A, 4);
delay(500);
ledcWriteNote(TONE_PWM_CHANNEL, NOTE_B, 4);
delay(500);
ledcWriteNote(TONE_PWM_CHANNEL, NOTE_C, 5);
delay(500);
}
download arduino IDE source code file:
play tone.zip (Size: 369 bytes / Downloads: 311)
const int TONE_OUTPUT_PIN = 26;
const int TONE_PWM_CHANNEL = 0;
void setup() {
ledcAttachPin(TONE_OUTPUT_PIN, TONE_PWM_CHANNEL);
}
void loop() {
// Plays the middle C scale
ledcWriteNote(TONE_PWM_CHANNEL, NOTE_C, 4);
delay(500);
ledcWriteNote(TONE_PWM_CHANNEL, NOTE_D, 4);
delay(500);
ledcWriteNote(TONE_PWM_CHANNEL, NOTE_E, 4);
delay(500);
ledcWriteNote(TONE_PWM_CHANNEL, NOTE_F, 4);
delay(500);
ledcWriteNote(TONE_PWM_CHANNEL, NOTE_G, 4);
delay(500);
ledcWriteNote(TONE_PWM_CHANNEL, NOTE_A, 4);
delay(500);
ledcWriteNote(TONE_PWM_CHANNEL, NOTE_B, 4);
delay(500);
ledcWriteNote(TONE_PWM_CHANNEL, NOTE_C, 5);
delay(500);
}
download arduino IDE source code file:
play tone.zip (Size: 369 bytes / Downloads: 311)