[244] | 1 | /*
|
---|
| 2 | Copyright (C) 2012 Paulo Marques (pjp.marques@gmail.com)
|
---|
| 3 |
|
---|
| 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
|
---|
| 5 | this software and associated documentation files (the "Software"), to deal in
|
---|
| 6 | the Software without restriction, including without limitation the rights to
|
---|
| 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
---|
| 8 | the Software, and to permit persons to whom the Software is furnished to do so,
|
---|
| 9 | subject to the following conditions:
|
---|
| 10 |
|
---|
| 11 | The above copyright notice and this permission notice shall be included in all
|
---|
| 12 | copies or substantial portions of the Software.
|
---|
| 13 |
|
---|
| 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
---|
| 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
---|
| 16 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
---|
| 17 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
---|
| 18 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
---|
| 19 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
---|
| 20 | */
|
---|
| 21 |
|
---|
| 22 | /*
|
---|
| 23 | * Library for controlling a chain of RGB LEDs based on the P9813 protocol.
|
---|
| 24 | * E.g., supports the Grove Chainable RGB LED product.
|
---|
| 25 | *
|
---|
| 26 | * Information about the P9813 protocol obtained from:
|
---|
| 27 | * http://www.seeedstudio.com/wiki/index.php?title=Twig_-_Chainable_RGB_LED
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 |
|
---|
| 32 | #ifndef __ChainableLED_h__
|
---|
| 33 | #define __ChainableLED_h__
|
---|
| 34 |
|
---|
| 35 | #if defined (SPARK)
|
---|
| 36 | #include "application.h"
|
---|
| 37 | #else
|
---|
| 38 | #include "Arduino.h"
|
---|
| 39 | #endif
|
---|
| 40 |
|
---|
| 41 | #define _CL_RED 0
|
---|
| 42 | #define _CL_GREEN 1
|
---|
| 43 | #define _CL_BLUE 2
|
---|
| 44 | #define _CLK_PULSE_DELAY 20
|
---|
| 45 |
|
---|
| 46 | class ChainableLED
|
---|
| 47 | {
|
---|
| 48 | public:
|
---|
| 49 | ChainableLED(byte clk_pin, byte data_pin, byte number_of_leds);
|
---|
| 50 | ~ChainableLED();
|
---|
| 51 |
|
---|
| 52 | void init();
|
---|
| 53 | void setColorRGB(byte led, byte red, byte green, byte blue);
|
---|
| 54 | void setColorHSB(byte led, float hue, float saturation, float brightness);
|
---|
| 55 |
|
---|
| 56 | private:
|
---|
| 57 | byte _clk_pin;
|
---|
| 58 | byte _data_pin;
|
---|
| 59 | byte _num_leds;
|
---|
| 60 |
|
---|
| 61 | byte* _led_state;
|
---|
| 62 |
|
---|
| 63 | void clk(void);
|
---|
| 64 | void sendByte(byte b);
|
---|
| 65 | void sendColor(byte red, byte green, byte blue);
|
---|
| 66 | };
|
---|
| 67 |
|
---|
| 68 | #endif
|
---|
| 69 |
|
---|