Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[arduino source code for KC868-Uair-3] Let buzzer play tone
#1
// 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: 

.zip   play tone.zip (Size: 369 bytes / Downloads: 245)
Reply
#2
Hello, this is very nice, is there a way to do it also with Esphome?
thanks
Reply
#3
i have not tried. But use esphome lambda can do that.
Reply


Forum Jump:


Users browsing this thread: