Smart Home Automation Forum

Full Version: [arduino source code for KC868-Uair-3] Let buzzer play tone
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
// 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: 
[attachment=447]
Hello, this is very nice, is there a way to do it also with Esphome?
thanks
i have not tried. But use esphome lambda can do that.