Skip to content

shiliu-yang/SimpleLed

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SimpleLed

English | 中文

SimpleLed is an Arduino library that controls the on, off, and blink functions of LEDs. It's a particularly simple project that aims to control LED blinking without using blocking delays.

1. Including header files

You need to include SimpleLed.h in your project.

#include "SimpleLed.h"

2. Initialize LED

After initializing the LED pin, the LED will be set to the off state by default.

To turn on the LED when the pin output is high:

#define LED_PIN LED_BUILTIN

SimpleLed led(LED_PIN);

Or:

#define LED_PIN LED_BUILTIN

SimpleLed led(LED_PIN, HIGH);

To turn on the LED when the pin output is low:

#define LED_PIN LED_BUILTIN

SimpleLed led(LED_PIN, LOW);

3. Control LED

3.1 Turn on the LED

    led.setState(SimpleLed::LedState::ON);

Or:

    led.setState(1);

Or:

    led.on();

3.2 Turn off the LED

    led.setState(SimpleLed::LedState::OFF);

Or:

    led.setState(0);

Or:

    led.off();

3.3 Blink the LED

The LED switches state every 1s (on-1s->off-1s->on ->...) and you need to call update() in loop():

void setup() {
    led.setState(SimpleLed::LedState::BLINK, 1000);
}

void loop() {
    led.update();
}

Or:

void setup() {
    led.blink(1000);
}

void loop() {
    led.update();
}

About

SimpleLed is an Arduino library that controls the on, off, and blink functions of LEDs. It's a particularly simple project that aims to control LED blinking without using blocking delays.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages