Library for controlling LED strips or arrays based on the WS2801 3-Channel Constant Current LED Driver, like the SF 32LED/m addressable LED strip. Any two digital out capable pins can be used for clock & data. also includes a header that defines the standart HTML color names

Dependents:   ws2801_controller

Files at this revision

API Documentation at this revision

Comitter:
wertyfrog
Date:
Tue Jun 14 19:20:50 2011 +0000
Child:
1:363dd100d793
Commit message:
documentation test 1

Changed in this revision

HTML_color.h Show annotated file Show diff for this revision Revisions of this file
ws2801.cpp Show annotated file Show diff for this revision Revisions of this file
ws2801.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HTML_color.h	Tue Jun 14 19:20:50 2011 +0000
@@ -0,0 +1,145 @@
+#ifndef HTML_color_H
+#define HTML_color_H
+
+#define ALICEBLUE 0xF0F8FF
+#define ANTIQUEWHITE 0xFAEBD7
+#define AQUA 0x00FFFF
+#define AQUAMARINE 0x7FFFD4
+#define AZURE 0xF0FFFF
+#define BEIGE 0xF5F5DC
+#define BISQUE 0xFFE4C4
+#define BLACK 0x000000
+#define BLANCHEDALMOND 0xFFEBCD
+#define BLUE 0x0000FF
+#define BLUEVIOLET 0x8A2BE2
+#define BROWN 0xA52A2A
+#define BURLYWOOD 0xDEB887
+#define CADETBLUE 0x5F9EA0
+#define CHARTREUSE 0x7FFF00
+#define CHOCOLATE 0xD2691E
+#define CORAL 0xFF7F50
+#define CORNFLOWERBLUE 0x6495ED
+#define CORNSILK 0xFFF8DC
+#define CRIMSON 0xDC143C
+#define CYAN 0x00FFFF
+#define DARKBLUE 0x00008B
+#define DARKCYAN 0x008B8B
+#define DARKGOLDENROD 0xB8860B
+#define DARKGRAY 0xA9A9A9
+#define DARKGREEN 0x006400
+#define DARKKHAKI 0xBDB76B
+#define DARKMAGENTA 0x8B008B
+#define DARKOLIVEGREEN 0x556B2F
+#define DARKORANGE 0xFF8C00
+#define DARKORCHID 0x9932CC
+#define DARKRED 0x8B0000
+#define DARKSALMON 0xE9967A
+#define DARKSEAGREEN 0x8FBC8F
+#define DARKSLATEBLUE 0x483D8B
+#define DARKSLATEGRAY 0x2F4F4F
+#define DARKTURQUOISE 0x00CED1
+#define DARKVIOLET 0x9400D3
+#define DEEPPINK 0xFF1493
+#define DEEPSKYBLUE 0x00BFFF
+#define DIMGRAY 0x696969
+#define DODGERBLUE 0x1E90FF
+#define FIREBRICK 0xB22222
+#define FLORALWHITE 0xFFFAF0
+#define FORESTGREEN 0x228B22
+#define FUCHSIA 0xFF00FF
+#define GAINSBORO 0xDCDCDC
+#define GHOSTWHITE 0xF8F8FF
+#define GOLD 0xFFD700
+#define GOLDENROD 0xDAA520
+#define GRAY 0xBEBEBE
+#define GREEN 0x008000
+#define GREENYELLOW 0xADFF2F
+#define HONEYDEW 0xF0FFF0
+#define HOTPINK 0xFF69B4
+#define INDIANRED 0xCD5C5C
+#define INDIGO 0x4B0082
+#define IVORY 0xFFFFF0
+#define KHAKI 0xF0D58C
+#define LAVENDER 0xE6E6FA
+#define LAVENDERBLUSH 0xFFF0F5
+#define LAWNGREEN 0x7CFC00
+#define LEMONCHIFFON 0xFFFACD
+#define LIGHTBLUE 0xADD8E6
+#define LIGHTCORAL 0xF08080
+#define LIGHTCYAN 0xE0FFFF
+#define LIGHTGOLDENRODYELLOW 0xFAFAD2
+#define LIGHTGREEN 0x90EE90
+#define LIGHTGREY 0xD3D3D3
+#define LIGHTPINK 0xFFB6C1
+#define LIGHTSALMON 0xFFA07A
+#define LIGHTSEAGREEN 0x20B2AA
+#define LIGHTSKYBLUE 0x87CEFA
+#define LIGHTSLATEGRAY 0x778899
+#define LIGHTSTEELBLUE 0xB0C4DE
+#define LIGHTYELLOW 0xFFFFE0
+#define LIME 0x00FF00
+#define LIMEGREEN 0x32CD32
+#define LINEN 0xFAF0E6
+#define MAGENTA 0xFF00FF
+#define MAROON 0x800000
+#define MEDIUMAQUAMARINE 0x66CDAA
+#define MEDIUMBLUE 0x0000CD
+#define MEDIUMORCHID 0xBA55D3
+#define MEDIUMPURPLE 0x9370DB
+#define MEDIUMSEAGREEN 0x3CB371
+#define MEDIUMSLATEBLUE 0x7B68EE
+#define MEDIUMSPRINGGREEN 0x00FA9A
+#define MEDIUMTURQUOISE 0x48D1CC
+#define MEDIUMVIOLETRED 0xC71585
+#define MIDNIGHTBLUE 0x191970
+#define MINTCREAM 0xF5FFFA
+#define MISTYROSE 0xFFE4E1
+#define MOCCASIN 0xFFE4B5
+#define NAVAJOWHITE 0xFFDEAD
+#define NAVY 0x000080
+#define OLDLACE 0xFDF5E6
+#define OLIVE 0x808000
+#define OLIVEDRAB 0x6B8E23
+#define ORANGE 0xFFA500
+#define ORANGERED 0xFF4500
+#define ORCHID 0xDA70D6
+#define PALEGOLDENROD 0xEEE8AA
+#define PALEGREEN 0x98FB98
+#define PALETURQUOISE 0xAFEEEE
+#define PALEVIOLET xDB7093
+#define PAPAYAWHIP 0xFFEFD5
+#define PEACHPUFF 0xFFDAB9
+#define PERU 0xCD853F
+#define PINK 0xFFC0CB
+#define PLUM 0xDDA0DD
+#define POWDERBLUE 0xB0E0E6
+#define PURPLE 0x800080
+#define RED 0xFF0000
+#define ROSYBROWN 0xBC8F8F
+#define ROYALBLUE 0x4169E1
+#define SADDLEBROWN 0x8B4513
+#define SALMON 0xFA8072
+#define SANDYBROWN 0xF4A460
+#define SEAGREEN 0x2E8B57
+#define SEASHELL 0xFFF5EE
+#define SIENNA 0xA0522D
+#define SILVER 0xC0C0C0
+#define SKYBLUE 0x87CEEB
+#define SLATEBLUE 0x6A5ACD
+#define SLATEGRAY 0x708090
+#define SNOW 0xFFFAFA
+#define SPRINGGREEN 0x00FF7F
+#define STEELBLUE 0x4682B4
+#define TAN 0xD2B48C
+#define TEAL 0x008080
+#define THISTLE 0xD8BFD8
+#define TOMATO 0xFF6347
+#define TURQUOISE 0x40E0D0
+#define VIOLET 0xEE82EE
+#define WHEAT 0xF5DEB3
+#define WHITE 0xFFFFFF
+#define WHITESMOKE 0xF5F5F5
+#define YELLOW 0xFFFF00
+#define YELLOWGREEN 0x9ACD32
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ws2801.cpp	Tue Jun 14 19:20:50 2011 +0000
@@ -0,0 +1,78 @@
+#include "ws2801.h"
+#include "mbed.h"
+
+
+//------------------------------------------------------------------------------------------------------------
+ws2801::ws2801(PinName CKI, PinName SDI, int STRIP_LENGTH, int reset_delay) : _CKI(CKI), _SDI(SDI), _STRIP_LENGTH(STRIP_LENGTH), _reset_delay(reset_delay)
+{
+_level=100;
+//ws2801.clear();
+for(int bits = 0; bits <= _STRIP_LENGTH*24; bits++)
+  {
+  _CKI = 0;
+  _SDI = 0;
+  _CKI = 1;
+  }
+_CKI = 0;
+wait_us(_reset_delay);
+}
+//------------------------------------------------------------------------------------------------------------
+void ws2801::post(int *strip_colors)
+{
+
+int strip_colors_leveled[_STRIP_LENGTH];
+uint32_t mask;
+
+for(int LED_number = 0 ; LED_number < _STRIP_LENGTH ; LED_number++)
+  {
+  if(_level != 100)
+    {
+    int R = ((strip_colors[LED_number] & 0x00ff0000) >> 16)*_level/100;
+    int G = ((strip_colors[LED_number] & 0x0000ff00) >> 8)*_level/100;
+    int B = (strip_colors[LED_number] & 0x000000ff)*_level/100;
+    strip_colors_leveled[LED_number] = (R << 16)|(G << 8)|B;
+    }
+  else strip_colors_leveled[LED_number] = strip_colors[LED_number];
+  int this_led_color = strip_colors_leveled[LED_number]; //24 bits of color data
+  for(char color_bit = 23 ; color_bit != 255 ; color_bit--)
+    { 
+    _CKI = 0;
+    mask = 1 << color_bit;
+    if(this_led_color & mask)_SDI = 1;
+    else _SDI = 0;
+    _CKI = 1; //Data is latched when clock goes high
+    }
+  }
+_CKI = 0;
+wait_us(_reset_delay); //Wait for 1ms to go into reset
+}
+//------------------------------------------------------------------------------------------------------------
+void ws2801::clear(void)
+{
+for(int bits = 0; bits <= _STRIP_LENGTH*24; bits++)
+  {
+  _CKI = 0;
+  _SDI = 0;
+  _CKI = 1;
+  }
+_CKI = 0;
+wait_us(_reset_delay);
+}
+//------------------------------------------------------------------------------------------------------------
+int ws2801::setlevel(int level)
+{
+if((level <= 100) && level)
+  {
+  _level = level;
+  return _level;
+  }
+return 0;
+}
+
+//------------------------------------------------------------------------------------------------------------
+int ws2801::setdelay(int reset_delay)
+{
+if(reset_delay <= 0x0fffffff)_reset_delay = reset_delay;
+return _reset_delay;
+}
+//---------EOF---------------EOF------------------------------------------------------------------------------
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ws2801.h	Tue Jun 14 19:20:50 2011 +0000
@@ -0,0 +1,64 @@
+#ifndef WS2801_H
+#define WS2801_H
+
+#include "mbed.h"
+#include "HTML_color.h"
+
+class ws2801 
+{
+public:
+    /** Create a new ws2801 object
+    * 
+    * More details about the function goes here
+    * and here
+    *
+    * @param CKI clock pin
+    * @param SDI data  pin
+    * @param STRIP_LENGTH number of ws2801 IC's i strip or array
+    * @param reset_delay delay in us to allow latching data
+    * @returns nothing   
+    */
+    ws2801(PinName CKI, PinName SDI, int STRIP_LENGTH = 32, int reset_delay = 800);
+    /** write RGB color data to strip or array
+    * 
+    * More details about the function goes here
+    * and here
+    *
+    * @param strip_colors array of color data, size must be 24xSTRIP_LENGHT bits
+    */
+    void post(int *strip_colors);
+    /** clears the array or strip (all off)
+    * 
+    * More details about the function goes here
+    * and here
+    *
+    */    
+    void clear(void);
+    /** dimms the entire array
+    * 
+    * More details about the function goes here
+    * and here
+    *
+    * @param level level in percent
+    * @returns current level
+    */
+    int setlevel(int level=100);
+    /** set reset/write delay
+    * 
+    * More details about the function goes here
+    * and here
+    *
+    * @param delay delay in us
+    * @returns delay in us
+    */    
+    int setdelay(int reset_delay=800);
+  
+private:  
+    DigitalOut _CKI;
+    DigitalOut _SDI;
+    int _STRIP_LENGTH;
+    int _level;
+    int _reset_delay;
+};
+
+#endif
\ No newline at end of file