我在NodeMCU上有一个简单的工作代码:
void setup() {
Serial.begin(9600);
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
// Serial.println("Let's turn on the LED Light");
// delay(1000); // wait for a second
// digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
// delay(5000); // wait for a second
// Serial.println("Let's turn off the LED Light");
// delay(1000); // wait for a second
// digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
// delay(5000); // wait for a second
int sensorValue = analogRead(A0); // read the input on analog pin 0
float voltage = sensorValue * (5.0 / 1023.0); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V)
float lux = voltage * 100;
// Serial.println(voltage); // print out the value you read
// Serial.println(lux);
// delay(1000);
if (lux > 150)
{
// Serial.println(lux);
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
}
else
{
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
}
}
这确实非常好,每当LDR看到的光大于150时,它就会打开LED,但是.....
如何使millis()计算LED点亮的时间/该值大于150?
我想在1分钟:52秒:152英里中显示时间,但是直到该值再次低于150(LED熄灭)时才显示时间。
有人可以帮助我吗?