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