程式碼 Led閃爍-範例-D1-Examplex-Basics-Blink
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
*/
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin 13 as an output.
pinMode(D13, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(D13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(D13, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
}
程式碼 Led閃爍-範例-D1-Examplex-Basics-BlinkWithoutDelay
/*
*/
int ledState = LOW;
unsigned long previousMillis = 0;
const long interval = 1000;
void setup() {
pinMode(D13, 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(D13, ledState);
}
}
因為我不知道影片檔怎樣上傳 ,不然影片檔比較真實