unsigned long preMills = 0;
int sw = 10;
int relay = 13;
int state = HIGH;
int reading;
int previous = LOW;
long time = 0;
long debounce = 100;
void setup()
{
pinMode(sw, INPUT_PULLUP);
pinMode(relay, OUTPUT);
}
void loop()
{
unsigned long Mills = millis();
reading = digitalRead(sw);
if (reading == HIGH && previous == LOW && millis() - time > debounce)
{
digitalWrite(13, LOW);
delay(10000); // 10초 on
digitalWrite(13, HIGH);
delay(10000); // 10초 off
Mills = millis();
}
else
{
digitalWrite(13, HIGH); // off
}
digitalWrite(relay, state);
previous = reading;
}
Post Views: 374
Leave a Reply
You must be logged in to post a comment.