Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Adafruit_WS2801 by
Adafruit_WS2801.h@3:dfffbd9f8ac6, 2014-06-03 (annotated)
- Committer:
- SomeRandomBloke
- Date:
- Tue Jun 03 15:45:14 2014 +0000
- Revision:
- 3:dfffbd9f8ac6
- Parent:
- 2:2fdaa13896a4
Updates with primitive graphics drawing
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| SomeRandomBloke | 0:582e1b9c1cc1 | 1 | #include "mbed.h" |
| SomeRandomBloke | 0:582e1b9c1cc1 | 2 | |
| SomeRandomBloke | 0:582e1b9c1cc1 | 3 | |
| SomeRandomBloke | 0:582e1b9c1cc1 | 4 | // Not all LED pixels are RGB order; 36mm type expects GRB data. |
| SomeRandomBloke | 0:582e1b9c1cc1 | 5 | // Optional flag to constructors indicates data order (default if |
| SomeRandomBloke | 0:582e1b9c1cc1 | 6 | // unspecified is RGB). As long as setPixelColor/getPixelColor are |
| SomeRandomBloke | 0:582e1b9c1cc1 | 7 | // used, other code can always treat 'packed' colors as RGB; the |
| SomeRandomBloke | 0:582e1b9c1cc1 | 8 | // library will handle any required translation internally. |
| SomeRandomBloke | 0:582e1b9c1cc1 | 9 | #define WS2801_RGB 0 |
| SomeRandomBloke | 0:582e1b9c1cc1 | 10 | #define WS2801_GRB 1 |
| SomeRandomBloke | 0:582e1b9c1cc1 | 11 | |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 12 | #define ws_swap(a, b) { int16_t t = a; a = b; b = t; } |
| SomeRandomBloke | 0:582e1b9c1cc1 | 13 | |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 14 | class Adafruit_WS2801 |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 15 | { |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 16 | |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 17 | public: |
| SomeRandomBloke | 0:582e1b9c1cc1 | 18 | |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 19 | // Configurable pins: |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 20 | Adafruit_WS2801(int16_t n, PinName dpin, PinName cpin, uint8_t order=WS2801_RGB); |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 21 | Adafruit_WS2801(int16_t x, int16_t y, PinName dpin, PinName cpin, uint8_t order=WS2801_RGB); |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 22 | // Use SPI hardware; specific pins only: |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 23 | Adafruit_WS2801(uint16_t n, uint8_t order=WS2801_RGB); |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 24 | // Adafruit_WS2801(uint16_t x, uint16_t y, uint8_t order=WS2801_RGB); |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 25 | // Empty constructor; init pins/strand length/data order later: |
| SomeRandomBloke | 1:6ff477690983 | 26 | // Adafruit_WS2801(); |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 27 | // Release memory (as needed): |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 28 | ~Adafruit_WS2801(); |
| SomeRandomBloke | 0:582e1b9c1cc1 | 29 | |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 30 | void begin(void); |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 31 | void show(void); |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 32 | void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b); |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 33 | void setPixelColor(uint16_t n, uint32_t c); |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 34 | void setPixelColor(int16_t x, int16_t y, uint8_t r, uint8_t g, uint8_t b); |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 35 | void setPixelColor(int16_t x, int16_t y, uint32_t c); |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 36 | void updatePins(PinName dpin, PinName cpin); // Change pins, configurable |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 37 | void updatePins(void); // Change pins, hardware SPI |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 38 | void updateLength(uint16_t n); // Change strand length |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 39 | void updateOrder(uint8_t order); // Change data order |
| SomeRandomBloke | 0:582e1b9c1cc1 | 40 | |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 41 | // Basic drawing functions, line and circle. These are only useful when pixels arranged in a matrix |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 42 | void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint32_t color); |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 43 | void drawFastVLine(int16_t x, int16_t y, int16_t h, uint32_t color); |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 44 | void drawFastHLine(int16_t x, int16_t y, int16_t w, uint32_t color); |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 45 | void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint32_t color); |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 46 | void drawCircle(int16_t x0, int16_t y0, int16_t r, uint32_t color); |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 47 | // void fillCircle(int16_t x0, int16_t y0, int16_t r, uint32_t color); |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 48 | // void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint32_t color); |
| SomeRandomBloke | 0:582e1b9c1cc1 | 49 | |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 50 | uint16_t numPixels(void); |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 51 | uint32_t getPixelColor(uint16_t n); |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 52 | |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 53 | private: |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 54 | |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 55 | uint16_t |
| SomeRandomBloke | 0:582e1b9c1cc1 | 56 | numLEDs, |
| SomeRandomBloke | 0:582e1b9c1cc1 | 57 | width, // used with matrix mode |
| SomeRandomBloke | 0:582e1b9c1cc1 | 58 | height; // used with matrix mode |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 59 | uint8_t |
| SomeRandomBloke | 0:582e1b9c1cc1 | 60 | *pixels, // Holds color values for each LED (3 bytes each) |
| SomeRandomBloke | 0:582e1b9c1cc1 | 61 | rgb_order // Color order; RGB vs GRB (or others, if needed in future) |
| SomeRandomBloke | 0:582e1b9c1cc1 | 62 | ; |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 63 | DigitalOut clkpin; |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 64 | DigitalOut datapin; // Clock & data pin numbers |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 65 | void alloc(uint16_t n); |
| SomeRandomBloke | 1:6ff477690983 | 66 | // startSPI(void); |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 67 | bool hardwareSPI; // If 'true', using hardware SPI |
| SomeRandomBloke | 3:dfffbd9f8ac6 | 68 | bool begun; // If 'true', begin() method was previously invoked |
| SomeRandomBloke | 0:582e1b9c1cc1 | 69 | }; |
