Library for Neopixel LEDS

Dependents:   MadPulseIMU

Fork of NeoStrip by Allen Wild

Committer:
jdawkins
Date:
Fri Sep 08 19:49:09 2017 +0000
Revision:
2:b33251737b7c
Parent:
0:9f237b11f0a8
Added Color Definitions to header

Who changed what in which revision?

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