问题描述
- Arduino 配合MQ-2烟雾传感器和LED灯实现烟雾报警器的程序怎么写?
-
这个程序哪里不对?请教各位大神,我是个文科小女生,完全不会写程序。。。。int led = 12 void setup() {
// put your setup code here, to run once:
pinMode=(led,output)}
void loop() {
// put your main code here, to run repeatedly:
int val = analogRead(0); //如果大于400则以10ms的间隔闪烁
if(val > 400){
blinkLED(10);
}else if(val > 300 && val < 400){
//如果大于300,小于400则以100ms的间隔闪烁
blinkLED(100);
}else if(val < 300 && val > 200){
blinkLED(1000);
}else{
//否则关闭
digitalWrite(led, LOW);
}
}
//闪烁函数
unsigned int blinkLED(int period){
unsigned long time = millis();
unsigned int signal;
if((time / period) % 2 == 0){
digitalWrite(led, HIGH);
}else{
digitalWrite(led, LOW);
}
}
时间: 2024-11-21 00:52:32