Smart Home Automation Forum

Full Version: [arduino source code for KC868-Uair-4] let Buzzer play music
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
#define Do 262
#define Re 294
#define Mi 330
#define Fa 350
#define Sol 393
#define La 441
#define Si 495
#define Doo 882
#define CC 525
#define DD 589
#define EE 661
#define AA 882
#include <ESP32Servo.h>

int musiclist[32]={Do,Re,Mi,Do,Do,Re,Mi,Do,Mi,Fa,Sol,Mi,Fa,Sol,Sol,La,Sol,Fa,Mi,Do,Sol,La,Sol,Fa,Mi,Do,Re,Sol,Do,Re,Sol,Do};

int timelist[32]={2,2,2,2,2,2,2,2,2,2,4,2,2,4,1,1,1,1,2,2,1,1,1,1,2,2,3,3,4,3,3,4};

void setup(){
  Serial.begin(115200);
  pinMode(26,OUTPUT);
}

void loop(){
  int i = 0;
    for (int i = 0; i <32; i = i + (1)) {
      tone(26, musiclist[i], 125*timelist[i]);
      delay(100);
    }
    delay(1000);
    i = 0;
  }
 
download arduino IDE source code file: 
[attachment=449]

Note: install "ESP32Servo" library online firstly.
[attachment=450]