您是否尝试自己回答这个问题?如果您提出您已经尝试过的建议会有所帮助,它将更容易帮助您:)
下面完全未经测试的建议,应该给你一些继续..
int SensorIn1 = 1;
int led_pin = 13;
long gone_high_time = 0; // set to zero if input is not high
// set to time input went high if input is high
void setup() {
Serial.begin (9600);
}
void loop() {
int val;
val = analogRead(SensorIn1);
Serial.println(val);
if (val > 1000) {
if (gone_high_time == 0) {
gone_high_time = millis();
} else if (millis() - gone_high_time > 5000) {
digitalWrite(led_pin, HIGH);
}
} else {
gone_high_time = 0;
digitalWrite(led_pin, LOW);
}
delay (100);
}