RGB LED library for Grove - Chainable RGB LED using P9813

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:
sam_grove
Date:
Sun May 03 01:34:41 2015 +0000
Revision:
1:50d0a66599e1
Parent:
0:24631ceaa38a
Bug fixes including RAM being clobbered if more than one LED was used. Other speed optimizations and simplifications.

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
sam_grove 1:50d0a66599e1 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
sam_grove 1:50d0a66599e1 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
sam_grove 1:50d0a66599e1 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
sam_grove 1:50d0a66599e1 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
sam_grove 1:50d0a66599e1 33 #ifndef CHAINABLELED_H
sam_grove 1:50d0a66599e1 34 #define CHAINABLELED_H
seeed 0:24631ceaa38a 35
seeed 0:24631ceaa38a 36 #include "mbed.h"
seeed 0:24631ceaa38a 37
seeed 0:24631ceaa38a 38 class ChainableLED
seeed 0:24631ceaa38a 39 {
seeed 0:24631ceaa38a 40 public:
sam_grove 1:50d0a66599e1 41 ChainableLED(PinName clk_pin, PinName data_pin, uint32_t number_of_leds);
seeed 0:24631ceaa38a 42 ~ChainableLED();
sam_grove 1:50d0a66599e1 43
sam_grove 1:50d0a66599e1 44 void setColorRGB(uint32_t led, uint8_t red, uint8_t green, uint8_t blue);
sam_grove 1:50d0a66599e1 45 void setColorHSB(uint32_t led, float hue, float saturation, float brightness);
sam_grove 1:50d0a66599e1 46 void ledsOff(void);
seeed 0:24631ceaa38a 47
seeed 0:24631ceaa38a 48 private:
seeed 0:24631ceaa38a 49 DigitalOut _clk_pin;
seeed 0:24631ceaa38a 50 DigitalOut _data_pin;
sam_grove 1:50d0a66599e1 51 uint32_t _num_leds;
sam_grove 1:50d0a66599e1 52
sam_grove 1:50d0a66599e1 53 typedef union {
sam_grove 1:50d0a66599e1 54 uint8_t rgb[3];
sam_grove 1:50d0a66599e1 55 struct {
sam_grove 1:50d0a66599e1 56 uint8_t r, g, b;
sam_grove 1:50d0a66599e1 57 };
sam_grove 1:50d0a66599e1 58 } led_val_t;
sam_grove 1:50d0a66599e1 59 led_val_t *_leds;
seeed 0:24631ceaa38a 60
seeed 0:24631ceaa38a 61 void sendByte(uint8_t b);
seeed 0:24631ceaa38a 62 void sendColor(uint8_t red, uint8_t green, uint8_t blue);
seeed 0:24631ceaa38a 63 };
seeed 0:24631ceaa38a 64
seeed 0:24631ceaa38a 65 #endif