Color pixels library using WS2812B and nRF51822

Dependents:   BLE_Color_Pixels Grove_Node BLE_HeartRate

Color pixels library using WS2812B and nRF51822 (16Hz)

http://www.seeedstudio.com/depot/bmz_cache/4/4f346dc15724a7b5a5c1383253aeefc9.image.530x397.jpg

It's for

Committer:
yihui
Date:
Thu Jul 31 11:14:14 2014 +0000
Revision:
0:1e1ce549ad91
Child:
1:0322642447e2
v1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yihui 0:1e1ce549ad91 1 /** Color pixels library using WS2812B and nRF51822 (16Hz)
yihui 0:1e1ce549ad91 2 * It's for
yihui 0:1e1ce549ad91 3 * + http://www.seeedstudio.com/depot/Digital-RGB-LED-FlexiStrip-60-LED-1-Meter-p-1666.html
yihui 0:1e1ce549ad91 4 * + http://www.seeedstudio.com/depot/WS2812B-Digital-RGB-LED-Waterproof-FlexiStrip-144-LEDmeter-2-meter-p-1869.html
yihui 0:1e1ce549ad91 5 * + http://www.seeedstudio.com/depot/WS2812B-RGB-LED-with-Integrated-Driver-Chip-10-PCs-pack-p-1675.html
yihui 0:1e1ce549ad91 6 *
yihui 0:1e1ce549ad91 7 * The MIT License (MIT)
yihui 0:1e1ce549ad91 8 *
yihui 0:1e1ce549ad91 9 * Copyright (c) 2014 Seeed Technology Inc.
yihui 0:1e1ce549ad91 10 *
yihui 0:1e1ce549ad91 11 * Permission is hereby granted, free of charge, to any person obtaining a copy
yihui 0:1e1ce549ad91 12 * of this software and associated documentation files (the "Software"), to deal
yihui 0:1e1ce549ad91 13 * in the Software without restriction, including without limitation the rights
yihui 0:1e1ce549ad91 14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
yihui 0:1e1ce549ad91 15 * copies of the Software, and to permit persons to whom the Software is
yihui 0:1e1ce549ad91 16 * furnished to do so, subject to the following conditions:
yihui 0:1e1ce549ad91 17
yihui 0:1e1ce549ad91 18 * The above copyright notice and this permission notice shall be included in
yihui 0:1e1ce549ad91 19 * all copies or substantial portions of the Software.
yihui 0:1e1ce549ad91 20
yihui 0:1e1ce549ad91 21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
yihui 0:1e1ce549ad91 22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
yihui 0:1e1ce549ad91 23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
yihui 0:1e1ce549ad91 24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
yihui 0:1e1ce549ad91 25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
yihui 0:1e1ce549ad91 26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
yihui 0:1e1ce549ad91 27 * THE SOFTWARE.
yihui 0:1e1ce549ad91 28 */
yihui 0:1e1ce549ad91 29
yihui 0:1e1ce549ad91 30 #ifndef __COLOR_PIXELS_H__
yihui 0:1e1ce549ad91 31 #define __COLOR_PIXELS_H__
yihui 0:1e1ce549ad91 32
yihui 0:1e1ce549ad91 33 #include <stdint.h>
yihui 0:1e1ce549ad91 34
yihui 0:1e1ce549ad91 35 class ColorPixels {
yihui 0:1e1ce549ad91 36 public:
yihui 0:1e1ce549ad91 37 /** Initilaze
yihui 0:1e1ce549ad91 38 * \param pin number of GPIO
yihui 0:1e1ce549ad91 39 * \param num number of pixels
yihui 0:1e1ce549ad91 40 */
yihui 0:1e1ce549ad91 41 ColorPixels(uint8_t pin, uint16_t num);
yihui 0:1e1ce549ad91 42
yihui 0:1e1ce549ad91 43 /**
yihui 0:1e1ce549ad91 44 */
yihui 0:1e1ce549ad91 45 ~ColorPixels();
yihui 0:1e1ce549ad91 46
yihui 0:1e1ce549ad91 47 /** Set the color of a pixel (without update)
yihui 0:1e1ce549ad91 48 * \param index index of a pixel
yihui 0:1e1ce549ad91 49 * \param r red
yihui 0:1e1ce549ad91 50 * \param g green
yihui 0:1e1ce549ad91 51 * \param b blue
yihui 0:1e1ce549ad91 52 */
yihui 0:1e1ce549ad91 53 void set_color(uint16_t index, uint8_t r, uint8_t g, uint8_t b);
yihui 0:1e1ce549ad91 54
yihui 0:1e1ce549ad91 55 /** Update
yihui 0:1e1ce549ad91 56 */
yihui 0:1e1ce549ad91 57 void update();
yihui 0:1e1ce549ad91 58
yihui 0:1e1ce549ad91 59 /** Turn off all pixels
yihui 0:1e1ce549ad91 60 */
yihui 0:1e1ce549ad91 61 void clear();
yihui 0:1e1ce549ad91 62
yihui 0:1e1ce549ad91 63 private:
yihui 0:1e1ce549ad91 64 typedef union {
yihui 0:1e1ce549ad91 65 struct {
yihui 0:1e1ce549ad91 66 uint8_t g, r, b;
yihui 0:1e1ce549ad91 67 };
yihui 0:1e1ce549ad91 68 uint32_t grb;
yihui 0:1e1ce549ad91 69 } color_t;
yihui 0:1e1ce549ad91 70
yihui 0:1e1ce549ad91 71 uint8_t pin;
yihui 0:1e1ce549ad91 72 uint16_t num;
yihui 0:1e1ce549ad91 73 color_t *colors;
yihui 0:1e1ce549ad91 74
yihui 0:1e1ce549ad91 75 };
yihui 0:1e1ce549ad91 76
yihui 0:1e1ce549ad91 77 #endif // __COLOR_PIXELS_H__