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:
parent
bdf2296a7d
commit
ac626ad9f8
@ -9,8 +9,7 @@
|
|||||||
There are two variants of the attach function: attach and attach_ms.
|
There are two variants of the attach function: attach and attach_ms.
|
||||||
The first one takes period in seconds, the second one in milliseconds.
|
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
|
The built-in LED will be blinking.
|
||||||
or connect an external one to TXD on other boards.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Ticker.h>
|
#include <Ticker.h>
|
||||||
@ -21,8 +20,8 @@ int count = 0;
|
|||||||
|
|
||||||
void flip()
|
void flip()
|
||||||
{
|
{
|
||||||
int state = digitalRead(1); // get the current state of GPIO1 pin
|
int state = digitalRead(LED_BUILTIN); // get the current state of GPIO1 pin
|
||||||
digitalWrite(1, !state); // set pin to the opposite state
|
digitalWrite(LED_BUILTIN, !state); // set pin to the opposite state
|
||||||
|
|
||||||
++count;
|
++count;
|
||||||
// when the counter reaches a certain value, start blinking like crazy
|
// when the counter reaches a certain value, start blinking like crazy
|
||||||
@ -38,8 +37,8 @@ void flip()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
pinMode(1, OUTPUT);
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
digitalWrite(1, LOW);
|
digitalWrite(LED_BUILTIN, LOW);
|
||||||
|
|
||||||
// flip the pin every 0.3s
|
// flip the pin every 0.3s
|
||||||
flipper.attach(0.3, flip);
|
flipper.attach(0.3, flip);
|
||||||
|
@ -8,8 +8,7 @@
|
|||||||
This sample runs two tickers that both call one callback function,
|
This sample runs two tickers that both call one callback function,
|
||||||
but with different arguments.
|
but with different arguments.
|
||||||
|
|
||||||
An LED connected to GPIO1 will be pulsing. Use a built-in LED on ESP-01
|
The built-in LED will be pulsing.
|
||||||
or connect an external one to TXD on other boards.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Ticker.h>
|
#include <Ticker.h>
|
||||||
@ -18,11 +17,11 @@ Ticker tickerSetHigh;
|
|||||||
Ticker tickerSetLow;
|
Ticker tickerSetLow;
|
||||||
|
|
||||||
void setPin(int state) {
|
void setPin(int state) {
|
||||||
digitalWrite(1, state);
|
digitalWrite(LED_BUILTIN, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
pinMode(1, OUTPUT);
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
digitalWrite(1, LOW);
|
digitalWrite(1, LOW);
|
||||||
|
|
||||||
// every 25 ms, call setPin(0)
|
// every 25 ms, call setPin(0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user