【发布时间】:2019-10-02 06:28:40
【问题描述】:
我的这部分代码在执行时以红色突出显示。我是初学者,所以请帮我解决它。错误出现在代码 else 部分之后的行中。
尝试使用谷歌搜索。
const int ledPin=13;//ledpin,flamepin and buzpin are not changed throughout the process
const int flamepin=A2;
const int buzpin=11;
const int thresold=200;// sets threshold value for flame sensor
int flamesensvalue=0;//initialize flamesensor reading
void setup()
{
Serial.begin(9600);
pinMode(ledPin,OUTPUT);
pinMode(flamepin,INPUT);
pinMode(buzpin,OUTPUT);
}
void loop()
{
flamesensvalue=analogRead(flamepin); // reads analog data from flame sensor
if (flamesensvalue<=thresold)
{ // compares reading from flame sensor with the threshold value
digitalWrite(ledpin,HIGH); //turns on led and buzzer
tone(buzpin,100);
delay(1000); //stops program for 1 second
} else
{
digitalWrite(ledpin,LOW);//turns led off led and buzzer
noTune(buzpin);
}
}
【问题讨论】:
-
请显示更多您的代码,尝试minimal reproducible example。你可以假设我们有相同的环境。
-
查看构建日志,是否出现构建错误?什么错误?请花一些时间阅读有关 how to ask good questions 和 this question checklist 的信息,并编辑您的问题以改进它。
-
@KenY-N
setup函数由 Arduino 框架自动调用。然后它在无限循环中调用loop。 -
请注意向我们展示minimal reproducible example 的建议。我们需要看看你包含了哪些头文件。
-
对不起,特别是那些目光敏锐的回答者。我认为是时候将其作为错字关闭了。其实好几个错别字....