Skip to content

Commit

Permalink
Official Release
Browse files Browse the repository at this point in the history
  • Loading branch information
ArduinoGetStarted authored Jan 26, 2022
0 parents commit b157b96
Show file tree
Hide file tree
Showing 14 changed files with 898 additions and 0 deletions.
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
## LED Library for Arduino - ezLED
This library is designed for Arduino, ESP32, ESP8266... to control LED: on, off, toggle, fade in/out, blink, blink the number of times, blink in a period of time. It is designed for not only beginners but also experienced users.

**ezLED** stands for **easy LED**, which mean that the library is easy to use.

Features
----------------------------
* Turn on/off
* Toggle between on and off
* Fade in/out
* Blink
* Blink with the number of times
* Blink in a period of time
* Cancel the blinking or fading anytime
* Support both control modes: CTRL_ANODE and CTRL_CATHODE
* Get the on/off LED's states: LED_OFF, LED_ON
* Get the operation LED's state: LED_IDLE, LED_DELAY, LED_FADING, LED_BLINKING
* All functions are non-blocking (without using delay() function)
* Easy to use with multiple LEDs

Available Functions
----------------------------
* ezLED(int pin)
* ezLED(int pin, int mode)
* void turnON()
* void turnON(unsigned long delayTime)
* void turnOFF()
* void turnOFF(unsigned long delayTime)
* void toggle()
* void toggle(unsigned long delayTime)
* void fade(int fadeFrom, int fadeTo, unsigned long fadeTime)
* void fade(int fadeFrom, int fadeTo, unsigned long fadeTime, unsigned long delayTime)
* void blink(unsigned long onTime, unsigned long offTime)
* void blink(unsigned long onTime, unsigned long offTime, unsigned long delayTime)
* void blinkInPeriod(unsigned long onTime, unsigned long offTime, unsigned long blinkTime)
* void blinkInPeriod(unsigned long onTime, unsigned long offTime, unsigned long blinkTime, unsigned long delayTime)
* void blinkNumberOfTimes(unsigned long onTime, unsigned long offTime, unsigned int numberOfTimes)
* void blinkNumberOfTimes(unsigned long onTime, unsigned long offTime, unsigned int numberOfTimes, unsigned long delayTime)
* void cancel(void)
* int getOnOff(void)
* int getState(void)
* void loop(void)


Available Examples
----------------------------
* [LED Blink](https://arduinogetstarted.com/library/led/example/arduino-led-blink)
* [LED Blink In Period](https://arduinogetstarted.com/library/led/example/arduino-led-blink-in-period)
* [LED Blink Number Of Times](https://arduinogetstarted.com/library/led/example/arduino-led-blink-number-of-times)
* [LED Fade In Fade Out](https://arduinogetstarted.com/library/led/example/arduino-led-fade-in-fade-out)
* [LED On Off](https://arduinogetstarted.com/library/led/example/arduino-led-on-off)
* [LED Toggle](https://arduinogetstarted.com/library/led/example/arduino-led-toggle)
* [Multiple LED](https://arduinogetstarted.com/library/led/example/arduino-multiple-led)
* [LED Array](https://arduinogetstarted.com/library/led/example/arduino-led-array)



How To Install the Library
----------------------------
* [ezLED Library Installization Guide](https://arduinogetstarted.com/tutorials/arduino-led-library)

References
----------------------------
* [ezLED Library Reference](https://arduinogetstarted.com/tutorials/arduino-led-library)
55 changes: 55 additions & 0 deletions examples/LEDArray/LEDArray.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
Created by ArduinoGetStarted.com
This example code is in the public domain
Tutorial page: https://arduinogetstarted.com/library/led/example/arduino-led-array
This example blinks 3 LED:
+ blink one LED forever
+ blink one LED in 5 seconds
+ blink one LED in 10 times
+ without using delay() function. This is a non-blocking example
*/

#include <ezLED.h> // ezLED library

#define NUM_LED 3 // three LEDs

#define PIN_LED_1 7
#define PIN_LED_2 8
#define PIN_LED_3 9

ezLED ledArray[NUM_LED] = {
ezLED(PIN_LED_1), // create ezLED object that attach to pin PIN_LED_1
ezLED(PIN_LED_2), // create ezLED object that attach to pin PIN_LED_2
ezLED(PIN_LED_3) // create ezLED object that attach to pin PIN_LED_3
};

void setup() {
Serial.begin(9600);

ledArray[0].blink(500, 500); // 500ms ON, 500ms OFF, blink immediately
ledArray[1].blinkInPeriod(100, 100, 5000); // 100ms ON, 100ms OFF, blink in 5 seconds, blink immediately
ledArray[2].blinkNumberOfTimes(250, 750, 10); // 250ms ON, 750ms OFF, repeat 10 times, blink immediately
}

void loop() {
for (int i = 0; i < NUM_LED; i++)
ledArray[i].loop(); // MUST call the led.loop() function in loop()

// print the operation state
for (int i = 0; i < NUM_LED; i++) {
Serial.print("LED ");
Serial.print(i + 1);

if (ledArray[i].getState() == LED_DELAY)
Serial.println(" DELAYING");
else if (ledArray[i].getState() == LED_BLINKING)
Serial.println(" BLINKING");
else if (ledArray[i].getState() == LED_IDLE)
Serial.println(" BLINK ENDED");
}

// DO SOMETHING HERE
}
32 changes: 32 additions & 0 deletions examples/LEDBlink/LEDBlink.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Created by ArduinoGetStarted.com
This example code is in the public domain
Tutorial page: https://arduinogetstarted.com/library/led/example/arduino-led-blink
This example blinks LED:
+ blink led
+ without using delay() function. This is a non-blocking example
*/

#include <ezLED.h> // ezLED library

ezLED led(9); // create a LED object that attach to pin 9

void setup() {
Serial.begin(9600);
led.blink(250, 750); // 250ms ON, 750ms OFF, blink immediately
//led.blink(250, 750, 1000); // 250ms ON, 750ms OFF, blink after 1 second
}

void loop() {
led.loop(); // MUST call the led.loop() function in loop()

if (led.getState() == LED_BLINKING)
Serial.println("BLINKING");
else if (led.getState() == LED_IDLE)
Serial.println("BLINK ENDED");

// To stop blinking immediately, call led.cancel() function
}
33 changes: 33 additions & 0 deletions examples/LEDBlinkInPeriod/LEDBlinkInPeriod.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Created by ArduinoGetStarted.com
This example code is in the public domain
Tutorial page: https://arduinogetstarted.com/library/led/example/arduino-led-blink-in-period
This example blinks LED:
+ blink 10 seconds
+ without using delay() function. This is a non-blocking example
*/

#include <ezLED.h> // ezLED library

ezLED led(9); // create a LED object that attach to pin 9

void setup() {
Serial.begin(9600);
led.blinkInPeriod(250, 750, 10000); // 250ms ON, 750ms OFF, blink in 10 seconds, blink immediately
//led.blinkInPeriod(250, 750, 10000, 1000); // 250ms ON, 750ms OFF, blink in 10 seconds, blink after 1 second
}

void loop() {
led.loop(); // MUST call the led.loop() function in loop()

if (led.getState() == LED_BLINKING)
Serial.println("BLINKING");
else if (led.getState() == LED_IDLE)
Serial.println("BLINK ENDED");


// To stop blinking immediately, call led.cancel() function
}
32 changes: 32 additions & 0 deletions examples/LEDBlinkNumberOfTimes/LEDBlinkNumberOfTimes.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Created by ArduinoGetStarted.com
This example code is in the public domain
Tutorial page: https://arduinogetstarted.com/library/led/example/arduino-led-blink-number-of-times
This example blinks an LED:
+ blink LED 10 times and then off
+ without using delay() function. This is a non-blocking example
*/

#include <ezLED.h> // ezLED library

ezLED led(9); // create a LED object that attach to pin 9

void setup() {
Serial.begin(9600);
led.blinkNumberOfTimes(250, 750, 10); // 250ms ON, 750ms OFF, repeat 10 times, blink immediately
//led.blinkNumberOfTimes(250, 750, 10, 1000); // 250ms ON, 750ms OFF, repeat 10 times, blink after 1 second
}

void loop() {
led.loop(); // MUST call the led.loop() function in loop()

if (led.getState() == LED_BLINKING)
Serial.println("BLINKING");
else if (led.getState() == LED_IDLE)
Serial.println("BLINK ENDED");

// To stop blinking immediately, call led.cancel() function
}
41 changes: 41 additions & 0 deletions examples/LEDFadeInFadeOut/LEDFadeInFadeOut.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Created by ArduinoGetStarted.com
This example code is in the public domain
Tutorial page: https://arduinogetstarted.com/library/led/example/arduino-led-fade-in-fade-out
This example fade LED:
+ fade in LED in 3 seconds
+ fade out LED in 3 seconds
+ without using delay() function. This is a non-blocking example
*/

#include <ezLED.h> // ezLED library

ezLED led(9); // create a LED object that attach to pin 9
bool isFadedIn = false;

void setup() {
Serial.begin(9600);
}

void loop() {
led.loop(); // MUST call the led1.loop() function in loop()

if (led.getState() == LED_IDLE) {
if (isFadedIn == false) {
Serial.println("FADING IN");
led.fade(0, 255, 3000); // fade in from 0 to 255 in 3000ms, fade immediately
//led.fade(0, 255, 3000, 1000); // fade in from 0 to 255 in 3000ms, fade after 1 second
isFadedIn = true;
} else {
Serial.println("FADING OUT");
led.fade(255, 0, 3000); // fade out from 255 to 0 in 3000ms, fade immediately
//led.fade(255, 0, 3000, 1000); // fade out from 255 to 0 in 3000ms, fade after 1 second
isFadedIn = false;
}
}

// To stop fading immediately, call led.cancel() function
}
39 changes: 39 additions & 0 deletions examples/LEDOnOff/LEDOnOff.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Created by ArduinoGetStarted.com
This example code is in the public domain
Tutorial page: https://arduinogetstarted.com/library/led/example/arduino-led-on-off
This example turn ON/OFF led according to state of button.
*/

#include <ezLED.h> // ezLED library

#define BUTTON_PIN 7

ezLED led(3); // create a LED object that attach to pin 3

void setup() {
Serial.begin(9600);
pinMode(BUTTON_PIN, INPUT_PULLUP);
}

void loop() {
led.loop(); // MUST call the led.loop() function in loop()

int buttonState = digitalRead(BUTTON_PIN);

if (buttonState == LOW) {
led.turnON(); // turn on immediately
//led.turnON(1000); // turn on after 1 second
} else {
led.turnOFF(); // turn off immediately
//led.turnOFF(1000); // turn off after 1 second
}

if (led.getOnOff() == LED_ON)
Serial.println("LED is ON");
else
Serial.println("LED is OFF");
}
35 changes: 35 additions & 0 deletions examples/LEDToggle/LEDToggle.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Created by ArduinoGetStarted.com
This example code is in the public domain
Tutorial page: https://arduinogetstarted.com/library/led/example/arduino-led-toggle
This example turn ON/OFF led according to state of button.
*/

#include <ezButton.h> // ezButton library https://arduinogetstarted.com/tutorials/arduino-button-library
#include <ezLED.h> // ezLED library

ezButton button(7); // create a button object that attach to pin 7
ezLED led(3); // create a LED object that attach to pin 3

void setup() {
Serial.begin(9600);
button.setDebounceTime(50); // set debounce time to 50ms
}

void loop() {
button.loop(); // MUST call the loop() function first
led.loop(); // MUST call the loop() function first

if (button.isPressed()) {
led.toggle(); // toggle immediately
//led.toggle(1000); // toggle after 1 second
}

if (led.getOnOff() == LED_ON)
Serial.println("LED is ON");
else
Serial.println("LED is OFF");
}
Loading

0 comments on commit b157b96

Please sign in to comment.