Driver for WS2812

Dependents:   ChrisRGB-Ring

Committer:
chris
Date:
Sat Aug 02 21:44:26 2014 +0000
Revision:
1:c278c3d136bb
Parent:
0:be22a9d4df5f
Child:
2:fa7ac5632be4
Library for driving WS2812 LEDs

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chris 0:be22a9d4df5f 1 /* Copyright (c) 2012 cstyles, MIT License
chris 0:be22a9d4df5f 2 *
chris 0:be22a9d4df5f 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
chris 0:be22a9d4df5f 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
chris 0:be22a9d4df5f 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
chris 0:be22a9d4df5f 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
chris 0:be22a9d4df5f 7 * furnished to do so, subject to the following conditions:
chris 0:be22a9d4df5f 8 *
chris 0:be22a9d4df5f 9 * The above copyright notice and this permission notice shall be included in all copies or
chris 0:be22a9d4df5f 10 * substantial portions of the Software.
chris 0:be22a9d4df5f 11 *
chris 0:be22a9d4df5f 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
chris 0:be22a9d4df5f 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
chris 0:be22a9d4df5f 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
chris 0:be22a9d4df5f 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
chris 0:be22a9d4df5f 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
chris 0:be22a9d4df5f 17 */
chris 0:be22a9d4df5f 18
chris 0:be22a9d4df5f 19 #ifndef WS2812_H
chris 0:be22a9d4df5f 20 #define WS2812_H
chris 0:be22a9d4df5f 21
chris 0:be22a9d4df5f 22 #include "mbed.h"
chris 0:be22a9d4df5f 23
chris 0:be22a9d4df5f 24 #define WS1 0x38
chris 0:be22a9d4df5f 25 #define WS0 0x30
chris 0:be22a9d4df5f 26 #define SPICLK 5000000
chris 0:be22a9d4df5f 27 #define SPIBPF 6
chris 0:be22a9d4df5f 28
chris 1:c278c3d136bb 29 //#define WS1 0xfc0
chris 1:c278c3d136bb 30 //#define WS0 0xf00
chris 1:c278c3d136bb 31 //#define SPICLK 10000000
chris 1:c278c3d136bb 32 //#define SPIBPF 12
chris 1:c278c3d136bb 33
chris 1:c278c3d136bb 34
chris 1:c278c3d136bb 35
chris 0:be22a9d4df5f 36 //!Library for the WS2812 RGB LED with integrated controller
chris 0:be22a9d4df5f 37 /*!
chris 0:be22a9d4df5f 38 The WS2812 is controller that is built into a range of LEDs
chris 0:be22a9d4df5f 39 */
chris 0:be22a9d4df5f 40 class WS2812
chris 0:be22a9d4df5f 41 {
chris 0:be22a9d4df5f 42 public:
chris 0:be22a9d4df5f 43 //!Creates an instance of the class.
chris 0:be22a9d4df5f 44 /*!
chris 0:be22a9d4df5f 45 Connect WS2812 address addr using SPI MOSI pins
chris 0:be22a9d4df5f 46 */
chris 0:be22a9d4df5f 47 WS2812(PinName d, int size);
chris 0:be22a9d4df5f 48
chris 0:be22a9d4df5f 49 /*!
chris 0:be22a9d4df5f 50 Destroys instance.
chris 0:be22a9d4df5f 51 */
chris 0:be22a9d4df5f 52 ~WS2812();
chris 0:be22a9d4df5f 53
chris 0:be22a9d4df5f 54 //!Reads the current temperature.
chris 0:be22a9d4df5f 55 /*!
chris 0:be22a9d4df5f 56 Reads the temperature register of the LM75B and converts it to a useable value.
chris 0:be22a9d4df5f 57 */
chris 0:be22a9d4df5f 58 void update (int buf[]);
chris 0:be22a9d4df5f 59 void setAll (int color);
chris 0:be22a9d4df5f 60 void useII (int d);
chris 0:be22a9d4df5f 61 void setII (unsigned char d);
chris 0:be22a9d4df5f 62
chris 0:be22a9d4df5f 63
chris 0:be22a9d4df5f 64 private:
chris 0:be22a9d4df5f 65
chris 0:be22a9d4df5f 66 int __size;
chris 0:be22a9d4df5f 67 unsigned char __II;
chris 0:be22a9d4df5f 68 int __use_II;
chris 0:be22a9d4df5f 69 SPI __spi;
chris 0:be22a9d4df5f 70
chris 0:be22a9d4df5f 71 void __write (int color);
chris 0:be22a9d4df5f 72
chris 0:be22a9d4df5f 73
chris 0:be22a9d4df5f 74 };
chris 0:be22a9d4df5f 75
chris 0:be22a9d4df5f 76 #endif