Color pixels library using WS2812B and nRF51822
Dependents: BLE_Color_Pixels Grove_Node BLE_HeartRate
color_pixels.h
00001 /** Color pixels library using WS2812B and nRF51822 (16Hz) 00002 * It's for 00003 * + http://www.seeedstudio.com/depot/Digital-RGB-LED-FlexiStrip-60-LED-1-Meter-p-1666.html 00004 * + http://www.seeedstudio.com/depot/WS2812B-Digital-RGB-LED-Waterproof-FlexiStrip-144-LEDmeter-2-meter-p-1869.html 00005 * + http://www.seeedstudio.com/depot/WS2812B-RGB-LED-with-Integrated-Driver-Chip-10-PCs-pack-p-1675.html 00006 * 00007 * The MIT License (MIT) 00008 * 00009 * Copyright (c) 2014 Seeed Technology Inc. 00010 * 00011 * Permission is hereby granted, free of charge, to any person obtaining a copy 00012 * of this software and associated documentation files (the "Software"), to deal 00013 * in the Software without restriction, including without limitation the rights 00014 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00015 * copies of the Software, and to permit persons to whom the Software is 00016 * furnished to do so, subject to the following conditions: 00017 00018 * The above copyright notice and this permission notice shall be included in 00019 * all copies or substantial portions of the Software. 00020 00021 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00022 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00023 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00024 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00025 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00026 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00027 * THE SOFTWARE. 00028 */ 00029 00030 #ifndef __COLOR_PIXELS_H__ 00031 #define __COLOR_PIXELS_H__ 00032 00033 #include <stdint.h> 00034 00035 typedef union { 00036 uint32_t rgb; 00037 struct { 00038 uint8_t r; 00039 uint8_t g; 00040 uint8_t b; 00041 }; 00042 } color_t; 00043 00044 /** Color pixels class using WS2812B and nRF51822 (16Hz) 00045 * 00046 * Example: 00047 * @code 00048 * #include "mbed.h" 00049 * #include "color_pixels.h" 00050 * 00051 * ColorPixels pixels(1, 32); 00052 * 00053 * int main() { 00054 * pixels.set_color(0, 0, 255, 0); 00055 * pixels.update(); 00056 * 00057 * while(1) { 00058 * } 00059 * } 00060 * @endcode 00061 */ 00062 class ColorPixels 00063 { 00064 public: 00065 /** Initilaze 00066 * \param pin number of GPIO 00067 * \param num number of pixels 00068 */ 00069 ColorPixels(uint8_t pin, uint16_t num); 00070 00071 ~ColorPixels(); 00072 00073 /** Set the color of a pixel (without update) 00074 * \param index index of a pixel 00075 * \param r red 00076 * \param g green 00077 * \param b blue 00078 */ 00079 void set_color(uint16_t index, uint8_t r, uint8_t g, uint8_t b); 00080 00081 void set_color(uint16_t index, uint32_t rgb); 00082 00083 void set_all_color(uint8_t r, uint8_t g, uint8_t b); 00084 00085 void rainbow(uint8_t r, uint8_t g, uint8_t b); 00086 00087 void rainbow(uint32_t rgb = 0x0000FF); 00088 00089 /** Update 00090 */ 00091 void update(); 00092 00093 /** Turn off all pixels 00094 */ 00095 void clear(); 00096 00097 private: 00098 typedef union { 00099 struct { 00100 uint8_t g, r, b; 00101 }; 00102 uint32_t grb; 00103 } grb_t; 00104 00105 uint8_t pin; 00106 uint16_t num; 00107 grb_t *colors; 00108 00109 }; 00110 00111 #endif // __COLOR_PIXELS_H__
Generated on Tue Jul 12 2022 19:06:55 by 1.7.2