This is a Shield Bot Library

Committer:
Kevin_Lee
Date:
Wed Sep 09 05:53:29 2015 +0000
Revision:
0:7535295d1670
Shield Bot Library

Who changed what in which revision?

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