Arduino

LightAPI DOCUMENTATION

Control many lights.

See Example  Public Methods  Release Notes
Overview

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().

Example Wiring

A LED and resistor wired to an Arduino Micro PWM 3 and ground.

Example SketchArduinoC++
Public Methods

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 constructor(pin)

Create a new light and pass in the PWM or Digital Arduino pin number.

EXAMPLE SKETCH
light
.on()

Turn on the light.

EXAMPLE SKETCH
light
.off()

Turn off the light.

EXAMPLE SKETCH
light
.setBrightness(value)

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.

EXAMPLE SKETCH
light
.setBrightnessPercent(value)

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.

EXAMPLE SKETCH
light
.isOn()

Returns true if the current light brightness is at 100%.

EXAMPLE SKETCH
light
.isOff()

Returns true if the current light brightness is at 0%.

EXAMPLE SKETCH
light
.getBrightness()

Returns an integer from 0 - 255 of the current light raw brightness.

EXAMPLE SKETCH
light
.getBrightnessPercent()

Returns an integer from 0 - 100 of the current light percentage brightness. This is the same as getBrightness() except with a smaller output range.

EXAMPLE SKETCH
light
.update()Update

Keep calculating brightness values over time. This must be called continuously within loop() in order to blink() or fade() the light.

EXAMPLE SKETCH
light
.blink(on_time, off_time, [times])Real-Time

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.

  • Light turns ON for the on_time
  • Then turns OFF for the off_time
  • Optionally repeats this cycle for the number of [times]
EXAMPLE SKETCH
light
.fade(up_time, on_time, down_time, off_time, [times])Real-Time

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.

  • Light performs a linear fade UP according to the up_time
  • Stays ON for the on_time
  • Linear fades DOWN over the course of the down_time
  • Stays OFF for the off_time
  • Optionally repeats this cycle for the number of [times]
EXAMPLE SKETCH