Seeed / Chainable_RGB_LED

Dependents:   Seeed_Grove_Chainable_RGB_LED_Example Temperature_Color SEEED_RGB_COLOR_LED_Example LoRaWAN_actility ... more

Fork of Chainable_RGB_LED by Seeed Studio

Committer:
seeed
Date:
Fri Aug 02 08:05:28 2013 +0000
Revision:
0:24631ceaa38a
Child:
1:50d0a66599e1
intial, port ChainableLED library from Arduino to mbed

Who changed what in which revision?

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