This allows an LPC1768 to take Art-Net data and send it to WS2812B LED's
Dependencies: mbed mbed-rtos EthernetInterface
NeoStrip/NeoStrip.h@15:c730bd607d9a, 2018-12-26 (annotated)
- Committer:
- tonydbeck
- Date:
- Wed Dec 26 21:05:02 2018 +0000
- Revision:
- 15:c730bd607d9a
Full Working Version - December 18
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tonydbeck | 15:c730bd607d9a | 1 | /** |
tonydbeck | 15:c730bd607d9a | 2 | * NeoStrip.h |
tonydbeck | 15:c730bd607d9a | 3 | * |
tonydbeck | 15:c730bd607d9a | 4 | * Allen Wild |
tonydbeck | 15:c730bd607d9a | 5 | * March 2014 |
tonydbeck | 15:c730bd607d9a | 6 | * |
tonydbeck | 15:c730bd607d9a | 7 | * Library for the control of Adafruit NeoPixel addressable RGB LEDs. |
tonydbeck | 15:c730bd607d9a | 8 | */ |
tonydbeck | 15:c730bd607d9a | 9 | |
tonydbeck | 15:c730bd607d9a | 10 | |
tonydbeck | 15:c730bd607d9a | 11 | #ifndef NEOSTRIP_H |
tonydbeck | 15:c730bd607d9a | 12 | #define NEOSTRIP_H |
tonydbeck | 15:c730bd607d9a | 13 | |
tonydbeck | 15:c730bd607d9a | 14 | #ifndef TARGET_LPC1768 |
tonydbeck | 15:c730bd607d9a | 15 | #error NeoStrip only supports the NXP LPC1768! |
tonydbeck | 15:c730bd607d9a | 16 | #endif |
tonydbeck | 15:c730bd607d9a | 17 | |
tonydbeck | 15:c730bd607d9a | 18 | // NeoColor struct definition to hold 24 bit |
tonydbeck | 15:c730bd607d9a | 19 | // color data for each pixel, in GRB order |
tonydbeck | 15:c730bd607d9a | 20 | typedef struct _NeoColor |
tonydbeck | 15:c730bd607d9a | 21 | { |
tonydbeck | 15:c730bd607d9a | 22 | uint8_t green; |
tonydbeck | 15:c730bd607d9a | 23 | uint8_t red; |
tonydbeck | 15:c730bd607d9a | 24 | uint8_t blue; |
tonydbeck | 15:c730bd607d9a | 25 | } NeoColor; |
tonydbeck | 15:c730bd607d9a | 26 | |
tonydbeck | 15:c730bd607d9a | 27 | /** |
tonydbeck | 15:c730bd607d9a | 28 | * NeoStrip objects manage the buffering and assigning of |
tonydbeck | 15:c730bd607d9a | 29 | * addressable NeoPixels |
tonydbeck | 15:c730bd607d9a | 30 | */ |
tonydbeck | 15:c730bd607d9a | 31 | class NeoStrip |
tonydbeck | 15:c730bd607d9a | 32 | { |
tonydbeck | 15:c730bd607d9a | 33 | public: |
tonydbeck | 15:c730bd607d9a | 34 | |
tonydbeck | 15:c730bd607d9a | 35 | /** |
tonydbeck | 15:c730bd607d9a | 36 | * Create a NeoStrip object |
tonydbeck | 15:c730bd607d9a | 37 | * |
tonydbeck | 15:c730bd607d9a | 38 | * @param pin The mbed data pin name |
tonydbeck | 15:c730bd607d9a | 39 | * @param N The number of pixels in the strip |
tonydbeck | 15:c730bd607d9a | 40 | */ |
tonydbeck | 15:c730bd607d9a | 41 | NeoStrip(PinName pin, int N); |
tonydbeck | 15:c730bd607d9a | 42 | |
tonydbeck | 15:c730bd607d9a | 43 | /** |
tonydbeck | 15:c730bd607d9a | 44 | * Set an overall brightness scale for the entire strip. |
tonydbeck | 15:c730bd607d9a | 45 | * When colors are set using setPixel(), they are scaled |
tonydbeck | 15:c730bd607d9a | 46 | * according to this brightness. |
tonydbeck | 15:c730bd607d9a | 47 | * |
tonydbeck | 15:c730bd607d9a | 48 | * Because NeoPixels are very bright and draw a lot of current, |
tonydbeck | 15:c730bd607d9a | 49 | * the brightness is set to 0.5 by default. |
tonydbeck | 15:c730bd607d9a | 50 | * |
tonydbeck | 15:c730bd607d9a | 51 | * @param bright The brightness scale between 0 and 1.0 |
tonydbeck | 15:c730bd607d9a | 52 | */ |
tonydbeck | 15:c730bd607d9a | 53 | void setBrightness(float bright); |
tonydbeck | 15:c730bd607d9a | 54 | |
tonydbeck | 15:c730bd607d9a | 55 | /** |
tonydbeck | 15:c730bd607d9a | 56 | * Set a single pixel to the specified color. |
tonydbeck | 15:c730bd607d9a | 57 | * |
tonydbeck | 15:c730bd607d9a | 58 | * This method (and all other setPixel methods) uses modulo-N arithmetic |
tonydbeck | 15:c730bd607d9a | 59 | * when addressing pixels. If p >= N, the pixel address will wrap around. |
tonydbeck | 15:c730bd607d9a | 60 | * |
tonydbeck | 15:c730bd607d9a | 61 | * @param p The pixel number (starting at 0) to set |
tonydbeck | 15:c730bd607d9a | 62 | * @param color A 24-bit color packed into a single int, |
tonydbeck | 15:c730bd607d9a | 63 | * using standard hex color codes (e.g. 0xFF0000 is red) |
tonydbeck | 15:c730bd607d9a | 64 | */ |
tonydbeck | 15:c730bd607d9a | 65 | void setPixel(int p, int color); |
tonydbeck | 15:c730bd607d9a | 66 | |
tonydbeck | 15:c730bd607d9a | 67 | /** |
tonydbeck | 15:c730bd607d9a | 68 | * Set a single pixel to the specified color, with red, green, and blue |
tonydbeck | 15:c730bd607d9a | 69 | * values in separate arguments. |
tonydbeck | 15:c730bd607d9a | 70 | */ |
tonydbeck | 15:c730bd607d9a | 71 | void setPixel(int p, uint8_t red, uint8_t green, uint8_t blue); |
tonydbeck | 15:c730bd607d9a | 72 | |
tonydbeck | 15:c730bd607d9a | 73 | /** |
tonydbeck | 15:c730bd607d9a | 74 | * Set n pixels starting at pixel p. |
tonydbeck | 15:c730bd607d9a | 75 | * |
tonydbeck | 15:c730bd607d9a | 76 | * @param p The first pixel in the strip to set. |
tonydbeck | 15:c730bd607d9a | 77 | * @param n The number of pixels to set. |
tonydbeck | 15:c730bd607d9a | 78 | * @param colors An array of length n containing the 24-bit colors for each pixel |
tonydbeck | 15:c730bd607d9a | 79 | */ |
tonydbeck | 15:c730bd607d9a | 80 | void setPixels(int p, int n, const int *colors); |
tonydbeck | 15:c730bd607d9a | 81 | |
tonydbeck | 15:c730bd607d9a | 82 | /** |
tonydbeck | 15:c730bd607d9a | 83 | * Reset all pixels in the strip to be of (0x000000) |
tonydbeck | 15:c730bd607d9a | 84 | */ |
tonydbeck | 15:c730bd607d9a | 85 | void clear(); |
tonydbeck | 15:c730bd607d9a | 86 | |
tonydbeck | 15:c730bd607d9a | 87 | /** |
tonydbeck | 15:c730bd607d9a | 88 | * Write the colors out to the strip; this method must be called |
tonydbeck | 15:c730bd607d9a | 89 | * to see any hardware effect. |
tonydbeck | 15:c730bd607d9a | 90 | * |
tonydbeck | 15:c730bd607d9a | 91 | * This function disables interrupts while the strip data is being sent, |
tonydbeck | 15:c730bd607d9a | 92 | * each pixel takes approximately 30us to send, plus a 50us reset pulse |
tonydbeck | 15:c730bd607d9a | 93 | * at the end. |
tonydbeck | 15:c730bd607d9a | 94 | */ |
tonydbeck | 15:c730bd607d9a | 95 | void write(); |
tonydbeck | 15:c730bd607d9a | 96 | |
tonydbeck | 15:c730bd607d9a | 97 | protected: |
tonydbeck | 15:c730bd607d9a | 98 | NeoColor *strip; // pixel data buffer modified by setPixel() and used by neo_out() |
tonydbeck | 15:c730bd607d9a | 99 | int N; // the number of pixels in the strip |
tonydbeck | 15:c730bd607d9a | 100 | int Nbytes; // the number of bytes of pixel data (always N*3) |
tonydbeck | 15:c730bd607d9a | 101 | float bright; // the master strip brightness |
tonydbeck | 15:c730bd607d9a | 102 | gpio_t gpio; // gpio struct for initialization and getting register addresses |
tonydbeck | 15:c730bd607d9a | 103 | }; |
tonydbeck | 15:c730bd607d9a | 104 | |
tonydbeck | 15:c730bd607d9a | 105 | #endif |
tonydbeck | 15:c730bd607d9a | 106 | |
tonydbeck | 15:c730bd607d9a | 107 |