https://github.com/geekbrother/ledwinker
Blink LED, change LED state async (without delay) PlatformIO and Arduino library.
https://github.com/geekbrother/ledwinker
arduino asynchronous esp32 esp8266 iot iot-device leds platformio
Last synced: 3 months ago
JSON representation
Blink LED, change LED state async (without delay) PlatformIO and Arduino library.
- Host: GitHub
- URL: https://github.com/geekbrother/ledwinker
- Owner: geekbrother
- License: apache-2.0
- Created: 2020-07-10T13:28:46.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-05-19T12:36:16.000Z (about 3 years ago)
- Last Synced: 2025-06-11T18:04:29.833Z (about 1 year ago)
- Topics: arduino, asynchronous, esp32, esp8266, iot, iot-device, leds, platformio
- Language: C++
- Homepage:
- Size: 53.7 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LedWinker

This is a tiny Platform.io (Arduino) library to control state of LED(s) in async manner.
Blink your LED (FAST or SLOW), ON, OFF. Change LED state in simple async manner without delays or blocking the main thread.
## Installation:
### PlatfromIO:
You can install library as a project dependency by adding it to `platformio.ini`:
```ini
[env:myenv]
platform = ...
framework = ...
board = ...
lib_deps =
LedWinker
...
```
## Usage:
### Initialization:
First of all you need to initialize your LED(s) for LedWinker by creating an instance of LedWinker.
You need to pass LED GPIO number as a paramater for constructor (see example below).
You can initialize as many LEDs as you wish by creating as many instances, they all will work async.
### States:
You can change the state of the LED by call `Wink(STATE)` method of the instance. STATE is the ENUM which includes `LED_ON, LED_OFF, LED_FAST, LED_SLOW` states.
Calling function doesn't hang main thread or make any delay. Changing state(s) will be full async.
You can get current state by calling `GetState()` method.
### Loop:
To work properly library needs to observe the main loop. Thats why you need to call `Loop()` method of each LedWink instance inside main loop() function of the program (see example below).
## Usage example:
```cpp
// LedWinker async LED control library usage example.
//
// Example program listen for commands from serial console to control the LED.
// Available commands: ON, OFF, SLOW, FAST
//
// Tested with Platform.io and Arduino
// Author: Max Kalashnikov
// Git Repo: https://github.com/geekbrother/LedWinker
#include
#include
#define LED_GPIO 13
// Initialize winker on LED GPIO number
LedWinker winker(LED_GPIO);
// serial incoming message
String incoming;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Start Winkering ;)");
Serial.println("Enter one of the state: ON | OFF | SLOW | FAST:");
}
void loop() {
// put your main code here, to run repeatedly:
// You need to put winker.Loop() inside your main loop() to observe the changes.
winker.Loop();
// Listen to commands from serial
// You can use ON, OFF, FAST (blinking), SLOW (blinking)
if (Serial.available() > 0) {
// read the incoming
incoming = Serial.readString();
// say what you got:
Serial.println(incoming);
// change led state depend on command
if (incoming == "ON") winker.Wink(LED_ON); // ON LED
if (incoming == "OFF") winker.Wink(LED_OFF); // OFF LED
if (incoming == "FAST") winker.Wink(LED_FAST); // Blink Fast
if (incoming == "SLOW") winker.Wink(LED_SLOW); // Blink Slow
}
}
```