![](/media/cache/profiles/e5bb391401062d002dd97a346b78ecee.jpg.50x50_q85.jpg)
Testing WS2801
Fork of ws2801 by
ws2801.h@3:2b362d164405, 2011-06-18 (annotated)
- Committer:
- wertyfrog
- Date:
- Sat Jun 18 00:33:14 2011 +0000
- Revision:
- 3:2b362d164405
- Parent:
- 2:a147efe1f3a8
- Child:
- 4:5e71151b8ad7
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wertyfrog | 3:2b362d164405 | 1 | /** |
wertyfrog | 3:2b362d164405 | 2 | * |
wertyfrog | 3:2b362d164405 | 3 | *Copyright (c) 2011 Thomas Olsson. |
wertyfrog | 3:2b362d164405 | 4 | * |
wertyfrog | 3:2b362d164405 | 5 | *Permission is hereby granted, free of charge, to any person obtaining a copy |
wertyfrog | 3:2b362d164405 | 6 | *of this software and associated documentation files (the "Software"), to deal |
wertyfrog | 3:2b362d164405 | 7 | *in the Software without restriction, including without limitation the rights |
wertyfrog | 3:2b362d164405 | 8 | *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
wertyfrog | 3:2b362d164405 | 9 | *copies of the Software, and to permit persons to whom the Software is |
wertyfrog | 3:2b362d164405 | 10 | *furnished to do so, subject to the following conditions: |
wertyfrog | 3:2b362d164405 | 11 | * |
wertyfrog | 3:2b362d164405 | 12 | *The above copyright notice and this permission notice shall be included in |
wertyfrog | 3:2b362d164405 | 13 | *all copies or substantial portions of the Software. |
wertyfrog | 3:2b362d164405 | 14 | * |
wertyfrog | 3:2b362d164405 | 15 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
wertyfrog | 3:2b362d164405 | 16 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
wertyfrog | 3:2b362d164405 | 17 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
wertyfrog | 3:2b362d164405 | 18 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
wertyfrog | 3:2b362d164405 | 19 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
wertyfrog | 3:2b362d164405 | 20 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
wertyfrog | 3:2b362d164405 | 21 | *THE SOFTWARE. |
wertyfrog | 3:2b362d164405 | 22 | * |
wertyfrog | 3:2b362d164405 | 23 | * |
wertyfrog | 3:2b362d164405 | 24 | */ |
wertyfrog | 3:2b362d164405 | 25 | |
wertyfrog | 0:b964d673c7db | 26 | #ifndef WS2801_H |
wertyfrog | 0:b964d673c7db | 27 | #define WS2801_H |
wertyfrog | 0:b964d673c7db | 28 | |
wertyfrog | 0:b964d673c7db | 29 | #include "mbed.h" |
wertyfrog | 0:b964d673c7db | 30 | #include "HTML_color.h" |
wertyfrog | 0:b964d673c7db | 31 | |
wertyfrog | 2:a147efe1f3a8 | 32 | |
wertyfrog | 3:2b362d164405 | 33 | /** WS2801 class, controlling LED strips or arrays like this http://www.sparkfun.com/products/10312 |
wertyfrog | 3:2b362d164405 | 34 | * |
wertyfrog | 3:2b362d164405 | 35 | * the WS2801 IC's are 5V but works well connected directly to mbed IO pins. |
wertyfrog | 3:2b362d164405 | 36 | * |
wertyfrog | 3:2b362d164405 | 37 | * You need a 5V power supply capable of about 2A to light up a 32 led strip, do NOT power from mbed(usb). |
wertyfrog | 3:2b362d164405 | 38 | * |
wertyfrog | 3:2b362d164405 | 39 | * the required reset delay is a blocking wait(), it can be lowered (or set to 0) if you want to use the |
wertyfrog | 3:2b362d164405 | 40 | * time for executing code instead, data sheet says 500us but i found it need at least 800us. |
wertyfrog | 2:a147efe1f3a8 | 41 | * |
wertyfrog | 2:a147efe1f3a8 | 42 | * Example: |
wertyfrog | 2:a147efe1f3a8 | 43 | * @code |
wertyfrog | 2:a147efe1f3a8 | 44 | * |
wertyfrog | 2:a147efe1f3a8 | 45 | * code exalple goes here |
wertyfrog | 2:a147efe1f3a8 | 46 | * |
wertyfrog | 2:a147efe1f3a8 | 47 | * @endcode |
wertyfrog | 2:a147efe1f3a8 | 48 | */ |
wertyfrog | 0:b964d673c7db | 49 | class ws2801 |
wertyfrog | 0:b964d673c7db | 50 | { |
wertyfrog | 0:b964d673c7db | 51 | public: |
wertyfrog | 0:b964d673c7db | 52 | /** Create a new ws2801 object |
wertyfrog | 0:b964d673c7db | 53 | * |
wertyfrog | 3:2b362d164405 | 54 | * |
wertyfrog | 0:b964d673c7db | 55 | * @param CKI clock pin |
wertyfrog | 0:b964d673c7db | 56 | * @param SDI data pin |
wertyfrog | 3:2b362d164405 | 57 | * @param STRIP_LENGTH number of ws2801 IC's i strip or array defaults to 32 |
wertyfrog | 3:2b362d164405 | 58 | * @param reset_delay delay in us to allow latching data defaults to 800 |
wertyfrog | 0:b964d673c7db | 59 | * @returns nothing |
wertyfrog | 0:b964d673c7db | 60 | */ |
wertyfrog | 0:b964d673c7db | 61 | ws2801(PinName CKI, PinName SDI, int STRIP_LENGTH = 32, int reset_delay = 800); |
wertyfrog | 0:b964d673c7db | 62 | /** write RGB color data to strip or array |
wertyfrog | 0:b964d673c7db | 63 | * |
wertyfrog | 3:2b362d164405 | 64 | * color data for each LED is 3 bytes int the order of rrggbb. |
wertyfrog | 3:2b362d164405 | 65 | * array must have STRIP_LENGTH number of elements |
wertyfrog | 0:b964d673c7db | 66 | * |
wertyfrog | 3:2b362d164405 | 67 | * @param strip_colors array of color data |
wertyfrog | 0:b964d673c7db | 68 | */ |
wertyfrog | 0:b964d673c7db | 69 | void post(int *strip_colors); |
wertyfrog | 0:b964d673c7db | 70 | /** clears the array or strip (all off) |
wertyfrog | 0:b964d673c7db | 71 | */ |
wertyfrog | 0:b964d673c7db | 72 | void clear(void); |
wertyfrog | 3:2b362d164405 | 73 | /** set level of the entire array 0-100% |
wertyfrog | 0:b964d673c7db | 74 | * |
wertyfrog | 3:2b362d164405 | 75 | * at low levels the colors may change because R,G or B |
wertyfrog | 3:2b362d164405 | 76 | * reaches 0. |
wertyfrog | 0:b964d673c7db | 77 | * |
wertyfrog | 0:b964d673c7db | 78 | * @param level level in percent |
wertyfrog | 0:b964d673c7db | 79 | * @returns current level |
wertyfrog | 0:b964d673c7db | 80 | */ |
wertyfrog | 3:2b362d164405 | 81 | int level(int level=0); |
wertyfrog | 3:2b362d164405 | 82 | /** get/set reset/write delay |
wertyfrog | 0:b964d673c7db | 83 | * |
wertyfrog | 3:2b362d164405 | 84 | * mainly for experimenting with reset values without recompiling, |
wertyfrog | 3:2b362d164405 | 85 | * leave at default to begin with & then lower to get faster execution. |
wertyfrog | 0:b964d673c7db | 86 | * |
wertyfrog | 0:b964d673c7db | 87 | * @param delay delay in us |
wertyfrog | 0:b964d673c7db | 88 | * @returns delay in us |
wertyfrog | 0:b964d673c7db | 89 | */ |
wertyfrog | 3:2b362d164405 | 90 | int delay(uint32_t reset_delay=800); |
wertyfrog | 0:b964d673c7db | 91 | |
wertyfrog | 0:b964d673c7db | 92 | private: |
wertyfrog | 0:b964d673c7db | 93 | DigitalOut _CKI; |
wertyfrog | 0:b964d673c7db | 94 | DigitalOut _SDI; |
wertyfrog | 0:b964d673c7db | 95 | int _STRIP_LENGTH; |
wertyfrog | 0:b964d673c7db | 96 | int _level; |
wertyfrog | 0:b964d673c7db | 97 | int _reset_delay; |
wertyfrog | 0:b964d673c7db | 98 | }; |
wertyfrog | 0:b964d673c7db | 99 | |
wertyfrog | 0:b964d673c7db | 100 | #endif |