Skip to content

Commit 2e1484e

Browse files
committed
Merge pull request #461 from probonopd/patch-1
ESP8266 Blink example for the blue LED on the ESP-01 module
2 parents 34f1053 + f024ef5 commit 2e1484e

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
ESP8266 Blink by Simon Peter
3+
Blink the blue LED on the ESP-01 module
4+
This example code is in the public domain
5+
6+
The blue LED on the ESP-01 module is connected to GPIO1
7+
(which is also the TXD pin; so we cannot use Serial.print() at the same time)
8+
9+
Note that this sketch uses BUILTIN_LED to find the pin with the internal LED
10+
*/
11+
12+
void setup() {
13+
pinMode(BUILTIN_LED, OUTPUT); // Initialize the BUILTIN_LED pin as an output
14+
}
15+
16+
// the loop function runs over and over again forever
17+
void loop() {
18+
digitalWrite(BUILTIN_LED, LOW); // Turn the LED on (Note that LOW is the voltage level
19+
// but actually the LED is on; this is because
20+
// it is acive low on the ESP-01)
21+
delay(1000); // Wait for a second
22+
digitalWrite(BUILTIN_LED, HIGH); // Turn the LED off by making the voltage HIGH
23+
delay(2000); // Wait for two seconds (to demonstrate the active low LED)
24+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
ESP8266 BlinkWithoutDelay by Simon Peter
3+
Blink the blue LED on the ESP-01 module
4+
Based on the Arduino Blink without Delay example
5+
This example code is in the public domain
6+
7+
The blue LED on the ESP-01 module is connected to GPIO1
8+
(which is also the TXD pin; so we cannot use Serial.print() at the same time)
9+
10+
Note that this sketch uses BUILTIN_LED to find the pin with the internal LED
11+
*/
12+
13+
int ledState = LOW;
14+
15+
unsigned long previousMillis = 0;
16+
const long interval = 1000;
17+
18+
void setup() {
19+
pinMode(BUILTIN_LED, OUTPUT);
20+
}
21+
22+
void loop()
23+
{
24+
unsigned long currentMillis = millis();
25+
if(currentMillis - previousMillis >= interval) {
26+
previousMillis = currentMillis;
27+
if (ledState == LOW)
28+
ledState = HIGH; // Note that this switches the LED *off*
29+
else
30+
ledState = LOW; // Note that this switches the LED *on*
31+
digitalWrite(BUILTIN_LED, ledState);
32+
}
33+
}

0 commit comments

Comments
 (0)