A conversion of the excellent Adafruit WS2801 library for Arduino to work on mbed

Dependents:   WiFiDipCortex_Cheerlights

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Adafruit_WS2801.h Source File

Adafruit_WS2801.h

00001 #include "mbed.h"
00002 
00003 
00004 // Not all LED pixels are RGB order; 36mm type expects GRB data.
00005 // Optional flag to constructors indicates data order (default if
00006 // unspecified is RGB).  As long as setPixelColor/getPixelColor are
00007 // used, other code can always treat 'packed' colors as RGB; the
00008 // library will handle any required translation internally.
00009 #define WS2801_RGB 0
00010 #define WS2801_GRB 1
00011 
00012 #define ws_swap(a, b) { int16_t t = a; a = b; b = t; }
00013 
00014 class Adafruit_WS2801
00015 {
00016 
00017 public:
00018 
00019     // Configurable pins:
00020     Adafruit_WS2801(int16_t n, PinName dpin, PinName cpin, uint8_t order=WS2801_RGB);
00021     Adafruit_WS2801(int16_t x, int16_t y, PinName dpin, PinName cpin, uint8_t order=WS2801_RGB);
00022     // Use SPI hardware; specific pins only:
00023     Adafruit_WS2801(uint16_t n, uint8_t order=WS2801_RGB);
00024 // Adafruit_WS2801(uint16_t x, uint16_t y, uint8_t order=WS2801_RGB);
00025     // Empty constructor; init pins/strand length/data order later:
00026 //  Adafruit_WS2801();
00027     // Release memory (as needed):
00028     ~Adafruit_WS2801();
00029 
00030     void begin(void);
00031     void show(void);
00032     void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b);
00033     void setPixelColor(uint16_t n, uint32_t c);
00034     void setPixelColor(int16_t x, int16_t y, uint8_t r, uint8_t g, uint8_t b);
00035     void setPixelColor(int16_t x, int16_t y, uint32_t c);
00036     void updatePins(PinName dpin, PinName cpin); // Change pins, configurable
00037     void updatePins(void); // Change pins, hardware SPI
00038     void updateLength(uint16_t n); // Change strand length
00039     void updateOrder(uint8_t order); // Change data order
00040 
00041     // Basic drawing functions, line and circle. These are only useful when pixels arranged in a matrix
00042     void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint32_t color);
00043     void drawFastVLine(int16_t x, int16_t y, int16_t h, uint32_t color);
00044     void drawFastHLine(int16_t x, int16_t y, int16_t w, uint32_t color);
00045     void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint32_t color);
00046     void drawCircle(int16_t x0, int16_t y0, int16_t r, uint32_t color);
00047 //    void fillCircle(int16_t x0, int16_t y0, int16_t r, uint32_t color);
00048 //    void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint32_t color);
00049 
00050     uint16_t numPixels(void);
00051     uint32_t getPixelColor(uint16_t n);
00052 
00053 private:
00054 
00055     uint16_t
00056     numLEDs,
00057     width,     // used with matrix mode
00058     height;    // used with matrix mode
00059     uint8_t
00060     *pixels,   // Holds color values for each LED (3 bytes each)
00061     rgb_order // Color order; RGB vs GRB (or others, if needed in future)
00062     ;
00063     DigitalOut  clkpin;
00064     DigitalOut  datapin;     // Clock & data pin numbers
00065     void    alloc(uint16_t n);
00066 //    startSPI(void);
00067     bool hardwareSPI; // If 'true', using hardware SPI
00068     bool  begun;       // If 'true', begin() method was previously invoked
00069 };