void setup()
{
pinMode(8, INPUT);
digitalWrite(8, HIGH);
pinMode(9, INPUT);
digitalWrite(9, HIGH);
pinMode(10, INPUT);
digitalWrite(10, HIGH);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
}
void loop()
{
int f = 0;
if(digitalRead(10) == LOW)
{
tone(7, 2210);
digitalWrite(13,HIGH);
f++;
}
if(digitalRead(9) == LOW)
{
tone(7, 2480);
digitalWrite(12,HIGH);
f++;
}
if(digitalRead(8) == LOW)
{
tone(7, 2780);
digitalWrite(11,HIGH);
f++;
}
if(f == 0)//用来关闭led和蜂鸣器,否则它会一直响
{
digitalWrite(11,LOW);
digitalWrite(12,LOW);
digitalWrite(13,LOW);
noTone(7);
}
}
Arduino入门案例:三音乐电子琴
最新推荐文章于 2024-04-22 22:53:37 发布