Smart Home Automation Forum
[arduino source code for KC868-Uair-4] let Buzzer play music - Printable Version

+- Smart Home Automation Forum (https://www.kincony.com/forum)
+-- Forum: Technical Support (https://www.kincony.com/forum/forumdisplay.php?fid=20)
+--- Forum: KC868-Uair (https://www.kincony.com/forum/forumdisplay.php?fid=31)
+--- Thread: [arduino source code for KC868-Uair-4] let Buzzer play music (/showthread.php?tid=1565)



[arduino source code for KC868-Uair-4] let Buzzer play music - admin - 12-30-2021

#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: 

.zip   play music.zip (Size: 486 bytes / Downloads: 280)

Note: install "ESP32Servo" library online firstly.