5 by 14 Neo array

Dependencies:   mbed

Committer:
RogerJKelly
Date:
Mon Jun 12 16:57:43 2017 +0000
Revision:
0:a32d1a85a830
working display using ARM to drive display.

Who changed what in which revision?

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