Reconsidered input pin and NC pin for SPI. Modified several functions interface and its contents.
Dependents: WS2812_out_of_specification_demo
WS2812.h@5:a07522fe36d4, 2014-08-18 (annotated)
- Committer:
- chris
- Date:
- Mon Aug 18 13:25:57 2014 +0000
- Revision:
- 5:a07522fe36d4
- Parent:
- 4:b230e85fc5e7
- Child:
- 6:583738208b96
Added the ability to write with offsets
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chris | 0:be22a9d4df5f | 1 | /* Copyright (c) 2012 cstyles, MIT License |
chris | 0:be22a9d4df5f | 2 | * |
chris | 4:b230e85fc5e7 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
chris | 4:b230e85fc5e7 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
chris | 4:b230e85fc5e7 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
chris | 4:b230e85fc5e7 | 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 | 4:b230e85fc5e7 | 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 | 4:b230e85fc5e7 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
chris | 4:b230e85fc5e7 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
chris | 4:b230e85fc5e7 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
chris | 4:b230e85fc5e7 | 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 | |
chris | 0:be22a9d4df5f | 30 | //!Library for the WS2812 RGB LED with integrated controller |
chris | 0:be22a9d4df5f | 31 | /*! |
chris | 0:be22a9d4df5f | 32 | The WS2812 is controller that is built into a range of LEDs |
chris | 0:be22a9d4df5f | 33 | */ |
chris | 0:be22a9d4df5f | 34 | class WS2812 |
chris | 0:be22a9d4df5f | 35 | { |
chris | 0:be22a9d4df5f | 36 | public: |
chris | 4:b230e85fc5e7 | 37 | //!Creates an instance of the class. |
chris | 4:b230e85fc5e7 | 38 | /*! |
chris | 4:b230e85fc5e7 | 39 | Connect WS2812 address addr using SPI MOSI pins |
chris | 4:b230e85fc5e7 | 40 | */ |
chris | 4:b230e85fc5e7 | 41 | WS2812(PinName d, int size); |
chris | 4:b230e85fc5e7 | 42 | |
chris | 4:b230e85fc5e7 | 43 | /*! |
chris | 4:b230e85fc5e7 | 44 | Destroys instance. |
chris | 4:b230e85fc5e7 | 45 | */ |
chris | 4:b230e85fc5e7 | 46 | ~WS2812(); |
chris | 4:b230e85fc5e7 | 47 | |
chris | 4:b230e85fc5e7 | 48 | //!Reads the current temperature. |
chris | 4:b230e85fc5e7 | 49 | /*! |
chris | 4:b230e85fc5e7 | 50 | Reads the temperature register of the LM75B and converts it to a useable value. |
chris | 4:b230e85fc5e7 | 51 | */ |
chris | 4:b230e85fc5e7 | 52 | void write (int buf[]); |
chris | 5:a07522fe36d4 | 53 | void write_offsets (int buf[],int r_offset=0, int g_offset=0, int b_offset=0); |
chris | 4:b230e85fc5e7 | 54 | void setAll(int colour); |
chris | 4:b230e85fc5e7 | 55 | |
chris | 4:b230e85fc5e7 | 56 | void useII(int d); |
chris | 4:b230e85fc5e7 | 57 | void setII(unsigned char II); |
chris | 4:b230e85fc5e7 | 58 | |
chris | 4:b230e85fc5e7 | 59 | |
chris | 0:be22a9d4df5f | 60 | |
chris | 0:be22a9d4df5f | 61 | private: |
chris | 0:be22a9d4df5f | 62 | |
chris | 4:b230e85fc5e7 | 63 | int __size; |
chris | 4:b230e85fc5e7 | 64 | unsigned char __II; |
chris | 4:b230e85fc5e7 | 65 | int __use_II; |
chris | 4:b230e85fc5e7 | 66 | SPI __spi; |
chris | 4:b230e85fc5e7 | 67 | void __write (int color); |
chris | 0:be22a9d4df5f | 68 | |
chris | 0:be22a9d4df5f | 69 | |
chris | 0:be22a9d4df5f | 70 | }; |
chris | 0:be22a9d4df5f | 71 | |
chris | 0:be22a9d4df5f | 72 | #endif |