A RGB LED Library for Arduino

To simplify dealing with multiple RGB strips or individual RGB LEDs I have written a small RGB library. This includes functions for direct set colors in RGB or HSV color model, and animation functionality of color transitions. The library is in a beta phase, is constantly evolving, but can already be used with absolutely NO WARRANTY.

Functions:

setRGB( int r, int g, int b )
setR( int r )
setG( int g )
setB( int b )

setHSV( float h, float s, float v )

animateStart()
animateStop()
animateColorsClear()
animateColorAdd( int col1, int col2, int col3, int t, int num=-1 )
animateSpeedSet( int speed )
animateColorTypeSet( byte type )

setBrightnessRGB( int r, int g, int b )
useBrightnessAdjust( boolean isAdjust )

Descriptions:

setRGB( int r, int g, int b )

Sets a color using the RGB color model and stops an eventually running animation.

Parameter: from 0 to 255 (0 is off, 255 highest color brightness level)

  • r = red
  • g = green
  • b = blue

Return value: none


setR( int r )

Set the amount of red on the RGB color model and stops an eventual animation.
Parameter: r = red, from 0 to 255 (0 is off, 255 highest color brightness level)
Return value: none


setG( int g )

Set the amount of green on the RGB color model and stops an eventual animation.
Parameter: g = green, from 0 to 255 (0 is off, 255 highest color brightness level)
Return value: none


setB( int b )

Set the amount of green on the RGB color model and stops an eventual animation.
Parameter: b = blue, from 0 to 255 (0 is off, 255 highest color brightness level)
Return value: none


setHSV( float h, float s, float v )

Sets a color using the HSV color model and stops an eventually running animation.
Parameter:

  • h = Hue as angle H, form 0 to 360 degrees on a Color wheel (around 0° for red, 120° for green, 240° for blue)
  • s = Saturation S, 0-100 in percent (0 = grey, 50 = half saturated color, 100 = pure color )
  • v =  Brightness V (value) 0-100 in percent (0 = off, 100 = full on)

Return value: none


animateStart()

Starts a color transition animation, works only if at least two colors are defined.


animateStop()

Stops a color transition animation. If called later animateStart () the color transition animation is continued from the stop point.


animateColorsClear()

Deletes all the colors of an animation and stops a running animation.


animateColorAdd( int col1, int col2, int col3, int t, int num=-1 )

Adds a color to the animation list. The colors depend on the currently selected animation color model.
Parameter:

  • col1-col3 depending on the selected color model (r,g,b or h,s,v)
  • t – Number of steps of the color transition to reach the color (col1-col3)
  • num=-1 -> Color is added at the end, num 0 – … color is replaced

Return value: boolean

  • true if color was added or replaced successful
  • false event of a fault (color was not added or replaced)

animateSpeedSet( int speed )

Changes the global speed of the selected color transition.
Parameter: speed
Return value: none


animateColorTypeSet( byte type )

Adds a color to the animation list. The colors depend on the currently selected animation color model.
Parameter: type is a constant: ANIMATETYPE_RGB for RGB or ANIMATETYPE_HSV for HSV
Return value: none


setBrightnessRGB( int r, int g, int b )

This function is used for “calibration” of the RGB strip. If all values ​​are set perfectly, the strip color should be pure white and is lit at the highest brightness. Calling the function will cause that the calibration function is applied immediately.


useBrightnessAdjust( boolean isAdjust )

Turns the calibration function, which is defined by setBrightnessRGB , on or off.
Parameter: isAdjust = true / false

  • true: calibration function is on
  • false: calibration function will not be used

Return value: none


Downloads:

Projects with the simtronyx_RGB_LED-Library:

Good?

Facebooktwittergoogle_plusredditpinterestlinkedinmailFacebooktwittergoogle_plusredditpinterestlinkedinmail

Leave a Reply

Your email address will not be published. Required fields are marked *

*