Control many lights and blink without delay using commands such as on(), off(), blink(), and fade(). Lights can be connected to PWM or Digital Arduino pins to work with this library.
PWM pins are necessary to enable all library features. Digital pins are supported by this library with special conditions documented in setBrightness() and fade().
#include <RBD_Timer.h> #include <RBD_Light.h> RBD::Light light(3); // PWM pin 3 void setup() { light.blink(250,250); } void loop() { light.update(); }
You can use this library without calling update() and most methods will function correctly. You must continuously call update() inside of loop() in order to use theReal-Time methods tagged below.
RBD::Light
Create a new light and pass in the PWM or Digital Arduino pin number.
RBD::Light light(3); // PWM pin 3 void setup() { ... }
Turn on the light.
void loop() { light.on(); }
Turn off the light.
void loop() { light.off(); }
PWM pins: pass in an integer between 0 - 255 to set the raw brightness of the light.
Digital pins: pass in an integer less than or equal to 127 to turn off the light. Pass in an integer greater than or equal to 128 to turn on the light.
void loop() { light.setBrightness(128); // about 50% brightness }
Pass in an integer between 0 - 100 to set the percentage brightness of the light. This is the same as setBrightness() except with a smaller input domain.
void loop() { light.setBrightnessPercent(75); // 75% brightness }
Returns true if the current light brightness is at 100%.
void loop() { if(light.isOn()) { ... } }
Returns true if the current light brightness is at 0%.
void loop() { if(light.isOff()) { ... } }
Returns an integer from 0 - 255 of the current light raw brightness.
void loop() { light.getBrightness(); }
Returns an integer from 0 - 100 of the current light percentage brightness. This is the same as getBrightness() except with a smaller output range.
void loop() { light.getBrightnessPercent(); }
Keep calculating brightness values over time. This must be called continuously within loop() in order to blink() or fade() the light.
void loop() { light.update(); }
Pass in unsigned longs for the on time and off time values in milliseconds. Pass in an integer for the last parameter for the number of times the light should blink, which is [optional] and can be left out to make the light repeat the blink cycle forever.
void setup() { light.blink(1000,500,25); } void loop() { light.update(); }
PWM pins: need unsigned longs passed in for the up, on, down, and off time values in milliseconds. Pass in an integer for the last parameter for the number of times the light should fade, which is [optional] and can be left out to make the light repeat the fade cycle forever.
Digital pins: behave the same as PWM pins except they will blink the light (when increasing past 50% brightness) instead of appearing as a linear fade.
void setup() { light.fade(2500,250,2000,750,1000); } void loop() { light.update(); }