NeoPixel NeoMatrix 8x8 RGB LED library. Product found at https://www.adafruit.com/products/1487. NeoCore.s from Allen Wild's NeoStrip library: http://developer.mbed.org/users/aswild/code/NeoStrip/

Dependents:   NeoMatrix_Demo

Fork of NeoStrip by Allen Wild

Committer:
tpowell33
Date:
Tue Mar 17 05:46:34 2015 +0000
Revision:
3:9a2779957e46
Parent:
2:97ef32687eba
Second publishing, fixed errors

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tpowell33 2:97ef32687eba 1 /**
tpowell33 3:9a2779957e46 2 * NeoMatrix.h
tpowell33 2:97ef32687eba 3 *
tpowell33 2:97ef32687eba 4 * Taylor Powell
tpowell33 2:97ef32687eba 5 * March 2015
tpowell33 2:97ef32687eba 6 *
tpowell33 2:97ef32687eba 7 * Library for the 8x8 grid array of Neopixel LEDs
tpowell33 2:97ef32687eba 8 *
tpowell33 2:97ef32687eba 9 */
tpowell33 2:97ef32687eba 10
tpowell33 2:97ef32687eba 11
tpowell33 2:97ef32687eba 12 #ifndef NEOARRAY_H
tpowell33 2:97ef32687eba 13 #define NEOARRAY_H
tpowell33 2:97ef32687eba 14
tpowell33 2:97ef32687eba 15 #ifndef TARGET_LPC1768
tpowell33 2:97ef32687eba 16 #error NeoArray only supports the NXP LPC1768
tpowell33 2:97ef32687eba 17 #endif
tpowell33 2:97ef32687eba 18
tpowell33 2:97ef32687eba 19 // NeoColor struct definition to hold 24 bit
tpowell33 2:97ef32687eba 20 // color data for each pixel, in GRB order
tpowell33 2:97ef32687eba 21 typedef struct _NeoColor
tpowell33 2:97ef32687eba 22 {
tpowell33 2:97ef32687eba 23 uint8_t green;
tpowell33 2:97ef32687eba 24 uint8_t red;
tpowell33 2:97ef32687eba 25 uint8_t blue;
tpowell33 2:97ef32687eba 26 } NeoColor;
tpowell33 2:97ef32687eba 27
tpowell33 2:97ef32687eba 28 /**
tpowell33 2:97ef32687eba 29 * NeoArr objects manage the buffering and assigning of
tpowell33 2:97ef32687eba 30 * addressable NeoPixels
tpowell33 2:97ef32687eba 31 */
tpowell33 2:97ef32687eba 32 class NeoArr
tpowell33 2:97ef32687eba 33 {
tpowell33 2:97ef32687eba 34 public:
tpowell33 2:97ef32687eba 35
tpowell33 2:97ef32687eba 36 /**
tpowell33 2:97ef32687eba 37 * Create a NeoArr object
tpowell33 2:97ef32687eba 38 *
tpowell33 2:97ef32687eba 39 * @param pin The mbed data pin name
tpowell33 2:97ef32687eba 40 * @param N The number of arrays chained together.
tpowell33 2:97ef32687eba 41 */
tpowell33 2:97ef32687eba 42 NeoArr(PinName pin, int N);
tpowell33 2:97ef32687eba 43
tpowell33 2:97ef32687eba 44 /**
tpowell33 2:97ef32687eba 45 * Sets the brightness of the entire array. All functions using set pixel are affected by this value.
tpowell33 2:97ef32687eba 46 * If a higher brightness is set, an external power supply may be necessary
tpowell33 2:97ef32687eba 47 *
tpowell33 2:97ef32687eba 48 * The default brightness is 0.5
tpowell33 2:97ef32687eba 49 *
tpowell33 2:97ef32687eba 50 * @param bright The brightness scaled between 0 and 1.0
tpowell33 2:97ef32687eba 51 */
tpowell33 2:97ef32687eba 52 void setBrightness(float bright);
tpowell33 2:97ef32687eba 53
tpowell33 2:97ef32687eba 54 /**
tpowell33 2:97ef32687eba 55 * Set a single pixel in the array to a specific color.
tpowell33 2:97ef32687eba 56 *
tpowell33 2:97ef32687eba 57 * @param idx The index of the array to write on. Indexing starts at 0 (use 0 if there is only one array)
tpowell33 2:97ef32687eba 58 * @param x The x co-ordinate of the pixel
tpowell33 2:97ef32687eba 59 * @param y The y co-ordinate of the pixel
tpowell33 2:97ef32687eba 60 * @param color Integer golding a 24 bit color using RGB hex indexing (e.g. 0xff0000 is red)
tpowell33 2:97ef32687eba 61 */
tpowell33 2:97ef32687eba 62 void setPixel(int idx, int x, int y, int color);
tpowell33 2:97ef32687eba 63
tpowell33 2:97ef32687eba 64 /**
tpowell33 2:97ef32687eba 65 * Set a single pixel in the array to a specific color with reg, blue, and blue values in seperate arguments
tpowell33 2:97ef32687eba 66 */
tpowell33 2:97ef32687eba 67 void setPixel(int idx, int x, int y, uint8_t red, uint8_t green, uint8_t blue);
tpowell33 2:97ef32687eba 68
tpowell33 2:97ef32687eba 69 /**
tpowell33 2:97ef32687eba 70 * Draws a line of a specific color between any two points
tpowell33 2:97ef32687eba 71 *
tpowell33 2:97ef32687eba 72 * @param idx The index of the array to write on. Indexing starts at 0 (use 0 if there is only one array)
tpowell33 2:97ef32687eba 73 * @param x1 The first x co-ordinate of the line
tpowell33 2:97ef32687eba 74 * @param y1 The first y co-ordinate of the line
tpowell33 2:97ef32687eba 75 * @param x2 The second x co-ordinate of the line
tpowell33 2:97ef32687eba 76 * @param y2 The second y co-ordinate of the line
tpowell33 2:97ef32687eba 77 * @param color Integer golding a 24 bit color using RGB hex indexing (e.g. 0xff0000 is red)
tpowell33 2:97ef32687eba 78 */
tpowell33 2:97ef32687eba 79
tpowell33 2:97ef32687eba 80 void drawLine(int idx, int x1, int y1, int x2, int y2, int color);
tpowell33 2:97ef32687eba 81
tpowell33 2:97ef32687eba 82 /**
tpowell33 2:97ef32687eba 83 * Draws a line of a specific color between any two points with reg, blue, and blue values in seperate arguments
tpowell33 2:97ef32687eba 84 */
tpowell33 2:97ef32687eba 85 void drawLine(int idx, int x1, int y1, int x2, int y2, uint8_t red, uint8_t green, uint8_t blue);
tpowell33 2:97ef32687eba 86 /**
tpowell33 2:97ef32687eba 87 * Draws a rectangle outline of a specific color given two opposite corner points
tpowell33 2:97ef32687eba 88 *
tpowell33 2:97ef32687eba 89 * @param idx The index of the array to write on. Indexing starts at 0 (use 0 if there is only one array)
tpowell33 2:97ef32687eba 90 * @param x1 The first x co-ordinate of a corner
tpowell33 2:97ef32687eba 91 * @param y1 The first y co-ordinate of a corner
tpowell33 2:97ef32687eba 92 * @param x2 The second x co-ordinate of a corner
tpowell33 2:97ef32687eba 93 * @param y2 The second y co-ordinate of a corner
tpowell33 2:97ef32687eba 94 * @param color Integer golding a 24 bit color using RGB hex indexing (e.g. 0xff0000 is red)
tpowell33 2:97ef32687eba 95 */
tpowell33 2:97ef32687eba 96
tpowell33 2:97ef32687eba 97 void drawRect(int idx, int x1, int y1, int x2, int y2, int color);
tpowell33 2:97ef32687eba 98
tpowell33 2:97ef32687eba 99 /**
tpowell33 2:97ef32687eba 100 * Draws a rectangle outline of a specific color given two opposite corner points with reg, blue, and blue values in seperate arguments
tpowell33 2:97ef32687eba 101 */
tpowell33 2:97ef32687eba 102 void drawRect(int idx, int x1, int y1, int x2, int y2, uint8_t red, uint8_t green, uint8_t blue);
tpowell33 2:97ef32687eba 103
tpowell33 2:97ef32687eba 104 /**
tpowell33 2:97ef32687eba 105 * Draws a filled rectangle of a specific color given two opposite corner points
tpowell33 2:97ef32687eba 106 *
tpowell33 2:97ef32687eba 107 * @param idx The index of the array to write on. Indexing starts at 0 (use 0 if there is only one array)
tpowell33 2:97ef32687eba 108 * @param x1 The first x co-ordinate of a corner
tpowell33 2:97ef32687eba 109 * @param y1 The first y co-ordinate of a corner
tpowell33 2:97ef32687eba 110 * @param x2 The second x co-ordinate of a corner
tpowell33 2:97ef32687eba 111 * @param y2 The second y co-ordinate of a corner
tpowell33 2:97ef32687eba 112 * @param color Integer golding a 24 bit color using RGB hex indexing (e.g. 0xff0000 is red)
tpowell33 2:97ef32687eba 113 */
tpowell33 2:97ef32687eba 114
tpowell33 2:97ef32687eba 115 void drawFilledRect(int idx, int x1, int y1, int x2, int y2, int color);
tpowell33 2:97ef32687eba 116
tpowell33 2:97ef32687eba 117 /**
tpowell33 2:97ef32687eba 118 * Draws a filled rectangle of a specific color given two opposite corner points with reg, blue, and blue values in seperate arguments
tpowell33 2:97ef32687eba 119 */
tpowell33 2:97ef32687eba 120 void drawFilledRect(int idx, int x1, int y1, int x2, int y2, uint8_t red, uint8_t green, uint8_t blue);
tpowell33 2:97ef32687eba 121
tpowell33 2:97ef32687eba 122 /**
tpowell33 2:97ef32687eba 123 * Fills the entire array screen with one color
tpowell33 2:97ef32687eba 124 *
tpowell33 2:97ef32687eba 125 * @param idx The index of the array to write on. Indexing starts at 0 (use 0 if there is only one array)
tpowell33 2:97ef32687eba 126 * @param color Integer golding a 24 bit color using RGB hex indexing (e.g. 0xff0000 is red)
tpowell33 2:97ef32687eba 127 */
tpowell33 2:97ef32687eba 128 void fillScreen(int idx, int color);
tpowell33 2:97ef32687eba 129
tpowell33 2:97ef32687eba 130 /**
tpowell33 2:97ef32687eba 131 * Fills the entire array screen with one color with reg, blue, and blue values in seperate arguments
tpowell33 2:97ef32687eba 132 *
tpowell33 2:97ef32687eba 133 */
tpowell33 2:97ef32687eba 134 void fillScreen(int idx, uint8_t red,uint8_t green, uint8_t blue);
tpowell33 2:97ef32687eba 135
tpowell33 2:97ef32687eba 136
tpowell33 2:97ef32687eba 137 /**
tpowell33 2:97ef32687eba 138 * Draws a triangle outline of a specific color given three corner points
tpowell33 2:97ef32687eba 139 *
tpowell33 2:97ef32687eba 140 * @param idx The index of the array to write on. Indexing starts at 0 (use 0 if there is only one array)
tpowell33 2:97ef32687eba 141 * @param x1 The first x co-ordinate of a corner
tpowell33 2:97ef32687eba 142 * @param y1 The first y co-ordinate of a corner
tpowell33 2:97ef32687eba 143 * @param x2 The second x co-ordinate of a corner
tpowell33 2:97ef32687eba 144 * @param y2 The second y co-ordinate of a corner
tpowell33 2:97ef32687eba 145 * @param x3 The third x co-ordinate of a corner
tpowell33 2:97ef32687eba 146 * @param y3 The third y co-ordinate of a corner
tpowell33 2:97ef32687eba 147 * @param color Integer golding a 24 bit color using RGB hex indexing (e.g. 0xff0000 is red)
tpowell33 2:97ef32687eba 148 */
tpowell33 2:97ef32687eba 149 void drawTriangle(int idx, int x1, int y1, int x2, int y2, int x3, int y3, int color);
tpowell33 2:97ef32687eba 150
tpowell33 2:97ef32687eba 151 /**
tpowell33 2:97ef32687eba 152 * Draws a triangle outline of a specific color given three corner points with reg, blue, and blue values in seperate arguments
tpowell33 2:97ef32687eba 153 */
tpowell33 2:97ef32687eba 154 void drawTriangle(int idx, int x1, int y1, int x2, int y2, int x3, int y3, uint8_t red, uint8_t green, uint8_t blue);
tpowell33 2:97ef32687eba 155 /**
tpowell33 2:97ef32687eba 156 * Draws a filled triangle of a specific color given three corner points
tpowell33 2:97ef32687eba 157 *
tpowell33 2:97ef32687eba 158 * @param idx The index of the array to write on. Indexing starts at 0 (use 0 if there is only one array)
tpowell33 2:97ef32687eba 159 * @param x1 The first x co-ordinate of a corner
tpowell33 2:97ef32687eba 160 * @param y1 The first y co-ordinate of a corner
tpowell33 2:97ef32687eba 161 * @param x2 The second x co-ordinate of a corner
tpowell33 2:97ef32687eba 162 * @param y2 The second y co-ordinate of a corner
tpowell33 2:97ef32687eba 163 * @param x3 The third x co-ordinate of a corner
tpowell33 2:97ef32687eba 164 * @param y3 The third y co-ordinate of a corner
tpowell33 2:97ef32687eba 165 * @param color Integer golding a 24 bit color using RGB hex indexing (e.g. 0xff0000 is red)
tpowell33 2:97ef32687eba 166 */
tpowell33 2:97ef32687eba 167
tpowell33 2:97ef32687eba 168 void drawFilledTriangle(int idx, int x1, int y1, int x2, int y2, int x3, int y3, int color);
tpowell33 2:97ef32687eba 169
tpowell33 2:97ef32687eba 170 /**
tpowell33 2:97ef32687eba 171 * Draws a filled triangle of a specific color given three corner points with reg, blue, and blue values in seperate arguments
tpowell33 2:97ef32687eba 172 */
tpowell33 2:97ef32687eba 173 void drawFilledTriangle(int idx, int x1, int y1, int x2, int y2, int x3, int y3, uint8_t red, uint8_t green, uint8_t blue);
tpowell33 2:97ef32687eba 174
tpowell33 2:97ef32687eba 175 /**
tpowell33 2:97ef32687eba 176 * Draws a single 6x8 character on the array. The character will be pulled from font.h
tpowell33 2:97ef32687eba 177 *
tpowell33 2:97ef32687eba 178 * @param idx The index of the array to write on. Indexing starts at 0 (use 0 if there is only one array)
tpowell33 2:97ef32687eba 179 * @param x The x co-ordinate of the lower left point of the character
tpowell33 2:97ef32687eba 180 * @param y The y co-ordinate of the lower left point of the character
tpowell33 2:97ef32687eba 181 * @para c The character to be drawn
tpowell33 2:97ef32687eba 182 * @param color Integer golding a 24 bit color using RGB hex indexing (e.g. 0xff0000 is red)
tpowell33 2:97ef32687eba 183 */
tpowell33 2:97ef32687eba 184 void drawChar(int idx, int x, int y, char c, int color);
tpowell33 2:97ef32687eba 185
tpowell33 2:97ef32687eba 186 /**
tpowell33 2:97ef32687eba 187 * Draws a single 6x8 character on the array. The character will be pulled from font.h with reg, blue, and blue values in seperate arguments
tpowell33 2:97ef32687eba 188 */
tpowell33 2:97ef32687eba 189 void drawChar(int idx, int x, int y, char c, uint8_t red, uint8_t green, uint8_t blue);
tpowell33 2:97ef32687eba 190
tpowell33 2:97ef32687eba 191
tpowell33 2:97ef32687eba 192 /**
tpowell33 2:97ef32687eba 193 * Displays a 64 bit image on board idx
tpowell33 2:97ef32687eba 194 *
tpowell33 2:97ef32687eba 195 * @param idx The index of the board
tpowell33 2:97ef32687eba 196 * @param colors An array of length 64 containing the image to be displayed
tpowell33 2:97ef32687eba 197 */
tpowell33 2:97ef32687eba 198 void showImage(int idx, const int *colors);
tpowell33 2:97ef32687eba 199
tpowell33 2:97ef32687eba 200 /**
tpowell33 2:97ef32687eba 201 * Clears all pixels on all boards (sets them all to 0)
tpowell33 2:97ef32687eba 202 */
tpowell33 2:97ef32687eba 203 void clear();
tpowell33 2:97ef32687eba 204
tpowell33 2:97ef32687eba 205 /**
tpowell33 2:97ef32687eba 206 * Write the colors out to the strip; this method must be called
tpowell33 2:97ef32687eba 207 * to see any hardware effect.
tpowell33 2:97ef32687eba 208 *
tpowell33 2:97ef32687eba 209 * This function disables interrupts while the strip data is being sent,
tpowell33 2:97ef32687eba 210 * each pixel takes approximately 30us to send, plus a 50us reset pulse
tpowell33 2:97ef32687eba 211 * at the end.
tpowell33 2:97ef32687eba 212 */
tpowell33 2:97ef32687eba 213 void write();
tpowell33 2:97ef32687eba 214
tpowell33 2:97ef32687eba 215
tpowell33 2:97ef32687eba 216 protected:
tpowell33 2:97ef32687eba 217 NeoColor *arr; // pixel data buffer modified by setPixel() and used by neo_out()
tpowell33 2:97ef32687eba 218 int N; // the number of pixels in the strip
tpowell33 2:97ef32687eba 219 int Nbytes; // the number of bytes of pixel data (always N*3)
tpowell33 2:97ef32687eba 220 float bright; // the master strip brightness
tpowell33 2:97ef32687eba 221 gpio_t gpio; // gpio struct for initialization and getting register addresses
tpowell33 2:97ef32687eba 222 };
tpowell33 2:97ef32687eba 223
tpowell33 2:97ef32687eba 224 #endif
tpowell33 2:97ef32687eba 225
tpowell33 2:97ef32687eba 226