我收到一个字符“1”然后蜂鸣器应该连续发声如果字符“2”收到,那么蜂鸣器应该关闭
void loop()
{
if (mySerial.available()) // there is some data to read
{
receivedChar = mySerial.read();
if (receivedChar == '1')
{
mySerial.println("Received a 1"); // for debugging
digitalWrite(LED, HIGH);
tone(buz, 1000, 500);
}
if (receivedChar == '2')
{
mySerial.println("Received a 2"); // for debugging
digitalWrite(LED, LOW);
}
}
}
但是这里蜂鸣器没有循环或重复。你能建议其他吗?只需蜂鸣器即可完成,无需任何LED发光。