A version of library with explicit flush() .

Fork of Chainable_RGB_LED by Seeed

Committer:
bor2
Date:
Sun Aug 26 00:29:00 2018 +0000
Revision:
2:d827cd87b212
Parent:
1:50d0a66599e1
Addressing problems that some B and G colors are swapped and some segments are powered by several strips.; ; Note this code doesn't compile in Eclipse and I'd like to figure out why.

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);
bor2 2:d827cd87b212 46 void flush();
sam_grove 1:50d0a66599e1 47 void ledsOff(void);
seeed 0:24631ceaa38a 48
seeed 0:24631ceaa38a 49 private:
seeed 0:24631ceaa38a 50 DigitalOut _clk_pin;
seeed 0:24631ceaa38a 51 DigitalOut _data_pin;
sam_grove 1:50d0a66599e1 52 uint32_t _num_leds;
sam_grove 1:50d0a66599e1 53
sam_grove 1:50d0a66599e1 54 typedef union {
sam_grove 1:50d0a66599e1 55 uint8_t rgb[3];
sam_grove 1:50d0a66599e1 56 struct {
sam_grove 1:50d0a66599e1 57 uint8_t r, g, b;
sam_grove 1:50d0a66599e1 58 };
sam_grove 1:50d0a66599e1 59 } led_val_t;
sam_grove 1:50d0a66599e1 60 led_val_t *_leds;
seeed 0:24631ceaa38a 61
seeed 0:24631ceaa38a 62 void sendByte(uint8_t b);
seeed 0:24631ceaa38a 63 void sendColor(uint8_t red, uint8_t green, uint8_t blue);
seeed 0:24631ceaa38a 64 };
seeed 0:24631ceaa38a 65
seeed 0:24631ceaa38a 66 #endif