3.蜂鸣器音乐代码

发布时间:2024-03-11 11:01

#define Do 495  
#define Re 556  
#define Mi 624  
#define Fa 661  
#define Sol 742  
#define La 833 
#define Si 935
#define hDo 990
#define hRe 1112  
#define hMi 1178 
#define hFa 1322  
#define hSol 1484  
#define hLa 1665
#define hSi 1869 
#define dDo 248 
#define dRe 278  
#define dMi 294  
#define dFa 330  
#define dSol 371  
#define dLa 416 
#define dSi 467
int pin=12; //自行选择作为输出的接口
int scale[]={Do,Re,Mi,Fa,Sol,La,Si,dDo,dRe,dMi,dFa,dSol,dLa,dSi,hDo,hRe,hMi,hFa,hSol,hLa,hSi};
int pu[100]={1,3,5,6,5,5,5,5,1,1,3,3,100,100,1,3,4,6,5,5,5,5,4,4,3,3,100,100,1,3,5,6,5,5,5,5,4,4,3,3,2,2,1,1,100,1,1,1,1,2,3,2,2,100,100};
void setup(){  
  pinMode(pin,OUTPUT);  
}  
void loop(){  
  for(int i=0;i<61;i++){
    if(pu[i]!=100) 
    {
      tone(pin,scale[pu[i]-1]); 
    }
    else 
      noTone(pin);  
    delay(200);
    noTone(pin);  
    delay(100);  
  }
  delay(5000);
}

B调——小宇

转载于:https://www.cnblogs.com/Sonny-xby/p/11073099.html

ItVuer - 免责声明 - 关于我们 - 联系我们

本网站信息来源于互联网,如有侵权请联系:561261067@qq.com

桂ICP备16001015号