|
发表于 2014-1-29 18:11:35
|
显示全部楼层
本帖最后由 pumpitup 于 2014-1-29 18:13 编辑
今天做了一下,蜂鸣器正接反接都响,但是声音略有不同,有一种略带点公鸭嗓子的感觉。
int soundport=4;
void setup() {
pinMode(soundport,OUTPUT);
}
int yfl[]={262,293,329,349,392,440,494};
int yf[]={523,586,658,697,783,879,987};
int yfh[]={1045,1171,1316,1393,1563,1755,1971};
void ps(int fre,int hl,float tim){
if(hl==0){
tone(soundport,yfl[fre-1]);
}else if(hl==1){
tone(soundport,yf[fre-1]);
}else if(hl==2){
tone(soundport,yfh[fre-1]);
}
delay((int)tim*1000);
noTone(soundport);
}
void loop() {
ps(1,2,1);
ps(2,2,2);
ps(3,2,3);
delay(1000);
/*
for(int i=0;i<2;i++){
tone(4,yf[2]);
delay(400);
tone(4,yf[0]);
delay(400);
}
*/
/* for(int i=0;i<=6;i++){
tone(4,yf);
delay(1000);
}
noTone(4);
delay(1000);
*/
} |
|