NGUYỄN VĂN SUM

Wednesday, November 1, 2017

Chớp tắt dùng định thời

Code:

// Crated by Nguyen Sum,
// https://nguyensumiot.wordpress.com/
// http://nguyensum.simplesite.com/
int ledPin = 16; // LED connected to digital pin 16
int ledState = LOW;
unsigned long previousMillis = 0;
const long interval = 1000;

void setup() {
pinMode(ledPin, OUTPUT);
}

void loop()
{
unsigned long currentMillis = millis();
if(currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (ledState == LOW)
ledState = HIGH; // Note that this switches the LED *off*
else
ledState = LOW; // Note that this switches the LED *on*
digitalWrite(ledPin, ledState);
}
}

No comments:

Post a Comment