unsigned long time1=0;
int analog_cds_pin=A0;
int led_pin=3;
int num_val;
void setup()
{
Serial.begin(9600);
pinMode(led_pin,OUTPUT);
}
void loop()
{
num_val=analogRead(analog_cds_pin);
if(num_val>125)
{
digitalWrite(led_pin,HIGH);
if(millis()-time1>2000)
{
time1=millis();
Serial.print(num_val);
Serial.println("led亮");
}
}
else
{
digitalWrite(led_pin,LOW);
if(millis()-time1>2000)
{
time1=millis();
Serial.print(num_val);
Serial.println("led不亮");
}
}
}
沒有留言:
張貼留言