1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

Use LED_BUILTIN so that it works w/o attaching external LED (#3452)

* Use LED_BUILTIN so that it works w/o attaching external LED

* Use built-in LED

* Clarify text
This commit is contained in:
probonopd 2017-09-21 11:22:27 +02:00 committed by Ivan Grokhotkov
parent bdf2296a7d
commit ac626ad9f8
2 changed files with 8 additions and 10 deletions

View File

@ -9,8 +9,7 @@
There are two variants of the attach function: attach and attach_ms.
The first one takes period in seconds, the second one in milliseconds.
An LED connected to GPIO1 will be blinking. Use a built-in LED on ESP-01
or connect an external one to TXD on other boards.
The built-in LED will be blinking.
*/
#include <Ticker.h>
@ -21,8 +20,8 @@ int count = 0;
void flip()
{
int state = digitalRead(1); // get the current state of GPIO1 pin
digitalWrite(1, !state); // set pin to the opposite state
int state = digitalRead(LED_BUILTIN); // get the current state of GPIO1 pin
digitalWrite(LED_BUILTIN, !state); // set pin to the opposite state
++count;
// when the counter reaches a certain value, start blinking like crazy
@ -38,8 +37,8 @@ void flip()
}
void setup() {
pinMode(1, OUTPUT);
digitalWrite(1, LOW);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
// flip the pin every 0.3s
flipper.attach(0.3, flip);

View File

@ -8,8 +8,7 @@
This sample runs two tickers that both call one callback function,
but with different arguments.
An LED connected to GPIO1 will be pulsing. Use a built-in LED on ESP-01
or connect an external one to TXD on other boards.
The built-in LED will be pulsing.
*/
#include <Ticker.h>
@ -18,11 +17,11 @@ Ticker tickerSetHigh;
Ticker tickerSetLow;
void setPin(int state) {
digitalWrite(1, state);
digitalWrite(LED_BUILTIN, state);
}
void setup() {
pinMode(1, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(1, LOW);
// every 25 ms, call setPin(0)