|
| 1 | +/********************************************************************* |
| 2 | + Basic snowflake code (without Bluetooth) |
| 3 | + |
| 4 | + Accompanies the Adafruit guide |
| 5 | + https://learn.adafruit.com/neopixel-matrix-snowflake-sweater |
| 6 | +
|
| 7 | + Adafruit invests time and resources providing this open source code, |
| 8 | + please support Adafruit and open-source hardware by purchasing |
| 9 | + products from Adafruit! |
| 10 | + |
| 11 | + MIT license, check LICENSE for more information |
| 12 | + All text above, and the splash screen below must be included in |
| 13 | + any redistribution |
| 14 | +*********************************************************************/ |
| 15 | +#include <Adafruit_NeoPixel.h> |
| 16 | +#include <Adafruit_GFX.h> |
| 17 | +#include <Adafruit_NeoMatrix.h> |
| 18 | +/*========================================================================= |
| 19 | + APPLICATION SETTINGS |
| 20 | + |
| 21 | + MATRIX DECLARATION Parameter 1 = width of NeoPixel matrix |
| 22 | + Parameter 2 = height of matrix |
| 23 | + Parameter 3 = pin number (most are valid) |
| 24 | + Parameter 4 = matrix layout flags, add together as needed: |
| 25 | + NEO_MATRIX_TOP, |
| 26 | + NEO_MATRIX_BOTTOM, |
| 27 | + NEO_MATRIX_LEFT, |
| 28 | + NEO_MATRIX_RIGHT Position of the FIRST LED in the matrix; pick two, e.g. |
| 29 | + NEO_MATRIX_TOP + NEO_MATRIX_LEFT for the top-left corner. |
| 30 | + NEO_MATRIX_ROWS, NEO_MATRIX_COLUMNS: LEDs are arranged in horizontal |
| 31 | + rows or in vertical columns, respectively; pick one or the other. |
| 32 | + NEO_MATRIX_PROGRESSIVE, |
| 33 | + NEO_MATRIX_ZIGZAG all rows/columns proceed in the same order, |
| 34 | + or alternate lines reverse direction; pick one. |
| 35 | + |
| 36 | + See example below for these values in action. |
| 37 | + |
| 38 | + Parameter 5 = pixel type flags, add together as needed: |
| 39 | + |
| 40 | + NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) |
| 41 | + NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) |
| 42 | + NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) |
| 43 | + NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) |
| 44 | + -----------------------------------------------------------------------*/ |
| 45 | + #define FACTORYRESET_ENABLE 1 |
| 46 | + |
| 47 | + #define PIN 6 // Which pin on the Arduino is connected to the NeoPixels? |
| 48 | + |
| 49 | +// Example for NeoPixel 8x8 Matrix. In this application we'd like to use it |
| 50 | +// with the back text positioned along the bottom edge. |
| 51 | +// When held that way, the first pixel is at the top left, and |
| 52 | +// lines are arranged in columns, zigzag order. The 8x8 matrix uses |
| 53 | +// 800 KHz (v2) pixels that expect GRB color data. |
| 54 | +Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(8, 8, PIN, |
| 55 | + NEO_MATRIX_TOP + NEO_MATRIX_LEFT + |
| 56 | + NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG, |
| 57 | + NEO_GRB + NEO_KHZ800); |
| 58 | +/*=========================================================================*/ |
| 59 | + |
| 60 | +void setup(void) |
| 61 | +{ |
| 62 | + matrix.begin(); |
| 63 | + matrix.setBrightness(40); |
| 64 | + |
| 65 | + matrix.fillScreen(0); |
| 66 | + matrix.show(); // This sends the updated pixel colors to the hardware. |
| 67 | +} |
| 68 | + |
| 69 | +void loop(void) |
| 70 | +{ |
| 71 | + matrix.fillScreen(0); |
| 72 | + SnowFlake1(matrix.Color(200, 200, 200)); |
| 73 | + matrix.show(); // This sends the updated pixel colors to the hardware. |
| 74 | + delay(500); |
| 75 | + matrix.fillScreen(0); |
| 76 | + SnowFlake2(matrix.Color(255, 0, 0)); |
| 77 | + matrix.show(); // This sends the updated pixel colors to the hardware. |
| 78 | + delay(500); |
| 79 | + matrix.fillScreen(0); |
| 80 | + SnowFlake3(matrix.Color(0, 255, 0)); |
| 81 | + matrix.show(); // This sends the updated pixel colors to the hardware. |
| 82 | + delay(500); |
| 83 | + matrix.fillScreen(0); |
| 84 | + SnowFlake4(matrix.Color(200, 200, 200)); |
| 85 | + matrix.show(); // This sends the updated pixel colors to the hardware. |
| 86 | + delay(500); |
| 87 | + matrix.fillScreen(0); |
| 88 | + SnowFlake5(matrix.Color(255, 0, 0)); |
| 89 | + matrix.show(); // This sends the updated pixel colors to the hardware. |
| 90 | + delay(500); |
| 91 | + matrix.fillScreen(0); |
| 92 | + SnowFlake6(matrix.Color(0, 255, 0)); |
| 93 | + matrix.show(); // This sends the updated pixel colors to the hardware. |
| 94 | + delay(500); |
| 95 | + matrix.fillScreen(0); |
| 96 | + SnowFlake7(matrix.Color(200, 200, 200)); |
| 97 | + matrix.show(); // This sends the updated pixel colors to the hardware. |
| 98 | + matrix.fillScreen(0); |
| 99 | + SnowFlake8(matrix.Color(255, 0, 0)); |
| 100 | + matrix.show(); // This sends the updated pixel colors to the hardware. |
| 101 | + delay(500); |
| 102 | +} |
| 103 | + |
| 104 | +void SnowFlake1(uint32_t c){ |
| 105 | + matrix.drawLine(0, 2, 2, 0, c); // x0, y0, x1, y1, color |
| 106 | + matrix.drawLine(4, 0, 6, 2, c); // x0, y0, x1, y1, color |
| 107 | + matrix.drawLine(0, 4, 2, 6, c); // x0, y0, x1, y1, color |
| 108 | + matrix.drawLine(4, 6, 6, 4, c); // x0, y0, x1, y1, color |
| 109 | + matrix.drawFastVLine(3, 0, 7, c); // x0, y0, length, color |
| 110 | + matrix.drawFastHLine(0, 3, 7, c); // x0, y0, length, color |
| 111 | + matrix.drawPixel(3, 3, 0); // x, y, color |
| 112 | +} |
| 113 | + |
| 114 | +void SnowFlake2(uint32_t c){ |
| 115 | + matrix.drawFastVLine(3, 0, 7, c); // x0, y0, length, color |
| 116 | + matrix.drawFastHLine(0, 3, 7, c); // x0, y0, length, color |
| 117 | + matrix.drawLine(1, 1, 5, 5, c); // x0, y0, x1, y1, color |
| 118 | + matrix.drawLine(1, 5, 5, 1, c); // x0, y0, x1, y1, color |
| 119 | + matrix.drawPixel(3, 3, 0); // x, y, color |
| 120 | +} |
| 121 | + |
| 122 | +void SnowFlake3(uint32_t c){ |
| 123 | + matrix.drawLine(0, 2, 2, 0, c); // x0, y0, x1, y1, color |
| 124 | + matrix.drawLine(0, 4, 4, 0, c); // x0, y0, x1, y1, color |
| 125 | + matrix.drawLine(1, 5, 5, 1, c); // x0, y0, x1, y1, color |
| 126 | + matrix.drawPixel(3, 3, 0); // x, y, color |
| 127 | + matrix.drawRect(2, 2, 3, 3, c); // x0, y0, width, height |
| 128 | + matrix.drawLine(2, 6, 6, 2, c); // x0, y0, x1, y1, color |
| 129 | + matrix.drawLine(4, 6, 6, 4, c); // x0, y0, x1, y1, color |
| 130 | +} |
| 131 | + |
| 132 | +void SnowFlake4(uint32_t c){ |
| 133 | + matrix.drawRect(2, 2, 3, 3, c); // x0, y0, width, height |
| 134 | + matrix.drawLine(0, 3, 3, 0, c); // x0, y0, x1, y1, color |
| 135 | + matrix.drawLine(3, 6, 6, 3, c); // x0, y0, x1, y1, color |
| 136 | + matrix.drawLine(4, 1, 5, 2, c); // x0, y0, x1, y1, color |
| 137 | + matrix.drawLine(1, 4, 2, 5, c); // x0, y0, x1, y1, color |
| 138 | + matrix.drawPixel(0, 0, c); // x, y, color |
| 139 | + matrix.drawPixel(0, 6, c); // x, y, color |
| 140 | + matrix.drawPixel(6, 0, c); // x, y, color |
| 141 | + matrix.drawPixel(6, 6, c); // x, y, color |
| 142 | + |
| 143 | +} |
| 144 | + |
| 145 | +void SnowFlake5(uint32_t c){ |
| 146 | + matrix.fillRect(1, 1, 5, 5, c); // x0, y0, width, height |
| 147 | + matrix.drawLine(0, 3, 3, 0, c); // x0, y0, x1, y1, color |
| 148 | + matrix.drawLine(3, 6, 6, 3, c); // x0, y0, x1, y1, color |
| 149 | + matrix.drawLine(1, 3, 3, 1, 0); // x0, y0, x1, y1, color |
| 150 | + matrix.drawLine(3, 5, 5, 3, 0); // x0, y0, x1, y1, color |
| 151 | + matrix.drawPixel(2, 4, 0); // x, y, color |
| 152 | + matrix.drawPixel(4, 2, 0); // x, y, color |
| 153 | + |
| 154 | +} |
| 155 | + |
| 156 | +void SnowFlake6(uint32_t c){ |
| 157 | + matrix.fillRect(1, 1, 5, 5, c); // x0, y0, width, height |
| 158 | + matrix.drawLine(1, 1, 5, 5, 0); // x0, y0, x1, y1, color |
| 159 | + matrix.drawLine(1, 5, 5, 1, 0); // x0, y0, x1, y1, color |
| 160 | + matrix.drawPixel(0, 3, c); // x, y, color |
| 161 | + matrix.drawPixel(3, 0, c); // x, y, color |
| 162 | + matrix.drawPixel(3, 6, c); // x, y, color |
| 163 | + matrix.drawPixel(6, 3, c); // x, y, color |
| 164 | +} |
| 165 | + |
| 166 | +void SnowFlake7(uint32_t c){ |
| 167 | + matrix.drawRect(2, 2, 3, 3, c); // x0, y0, width, height |
| 168 | + matrix.drawFastVLine(3, 0, 7, c); // x0, y0, length, color |
| 169 | + matrix.drawFastHLine(0, 3, 7, c); // x0, y0, length, color |
| 170 | + matrix.drawFastVLine(3, 0, 7, c); // x0, y0, length, color |
| 171 | + matrix.drawFastHLine(0, 3, 7, c); // x0, y0, length, color |
| 172 | + matrix.drawPixel(3, 3, 0); // x, y, color |
| 173 | + matrix.drawFastHLine(2, 0, 3, c); // x0, y0, length, color |
| 174 | + matrix.drawFastHLine(2, 6, 3, c); // x0, y0, length, color |
| 175 | + matrix.drawFastVLine(0, 2, 3, c); // x0, y0, length, color |
| 176 | + matrix.drawFastVLine(6, 2, 3, c); // x0, y0, length, color |
| 177 | +} |
| 178 | + |
| 179 | +void SnowFlake8(uint32_t c){ |
| 180 | + //four corners |
| 181 | + matrix.drawPixel(0, 0, c); // x, y, color |
| 182 | + matrix.drawPixel(0, 6, c); // x, y, color |
| 183 | + matrix.drawPixel(6, 0, c); // x, y, color |
| 184 | + matrix.drawPixel(6, 6, c); // x, y, color |
| 185 | + |
| 186 | + //upper left corner |
| 187 | + matrix.drawLine(0, 2, 2, 0, c); // x0, y0, x1, y1, color |
| 188 | + matrix.drawLine(0, 3, 3, 0, c); // x0, y0, x1, y1, color |
| 189 | + |
| 190 | + //center dot |
| 191 | + matrix.drawPixel(3, 3, c); // x, y, color |
| 192 | + |
| 193 | + //upper right corner |
| 194 | + matrix.drawLine(4, 0, 6, 2, c); // x0, y0, x1, y1, color |
| 195 | + matrix.drawLine(3, 0, 6, 3, c); // x0, y0, x1, y1, color |
| 196 | + |
| 197 | + //lower left corner |
| 198 | + matrix.drawLine(0, 3, 3, 6, c); // x0, y0, x1, y1, color |
| 199 | + matrix.drawLine(0, 4, 2, 6, c); // x0, y0, x1, y1, color |
| 200 | + |
| 201 | + //lower right corner |
| 202 | + matrix.drawLine(3, 6, 6, 3, c); // x0, y0, x1, y1, color |
| 203 | + matrix.drawLine(4, 6, 6, 4, c); // x0, y0, x1, y1, color |
| 204 | +} |
| 205 | +void SnowFlake9(uint32_t c){ |
| 206 | + //four corners |
| 207 | + matrix.drawPixel(0, 0, c); // x, y, color |
| 208 | + matrix.drawPixel(0, 6, c); // x, y, color |
| 209 | + matrix.drawPixel(6, 0, c); // x, y, color |
| 210 | + matrix.drawPixel(6, 6, c); // x, y, color |
| 211 | + |
| 212 | + //center dot |
| 213 | + matrix.drawPixel(3, 3, c); // x, y, color |
| 214 | + |
| 215 | + //four boxes near center |
| 216 | + matrix.drawRect(1, 1, 2, 2, c); // x0, y0, width, height |
| 217 | + matrix.drawRect(4, 1, 2, 2, c); // x0, y0, width, height |
| 218 | + matrix.drawRect(1, 4, 2, 2, c); // x0, y0, width, height |
| 219 | + matrix.drawRect(4, 4, 2, 2, c); // x0, y0, width, height |
| 220 | + |
| 221 | + //clear out corner pixel of boxes |
| 222 | + matrix.drawPixel(1, 1, 0); // x, y, color |
| 223 | + matrix.drawPixel(5, 1, 0); // x, y, color |
| 224 | + matrix.drawPixel(1, 5, 0); // x, y, color |
| 225 | + matrix.drawPixel(5, 5, 0); // x, y, color |
| 226 | +} |
| 227 | + |
| 228 | +void SnowFlake10(uint32_t c){ |
| 229 | + //lines across the corners |
| 230 | + matrix.drawLine(0, 1, 1, 0, c); // x0, y0, x1, y1, color |
| 231 | + matrix.drawLine(5, 0, 6, 1, c); // x0, y0, x1, y1, color |
| 232 | + matrix.drawLine(0, 5, 1, 6, c); // x0, y0, x1, y1, color |
| 233 | + matrix.drawLine(5, 6, 6, 5, c); // x0, y0, x1, y1, color |
| 234 | + |
| 235 | + //center dot |
| 236 | + matrix.drawPixel(3, 3, c); // x, y, color |
| 237 | + |
| 238 | + //four boxes near center |
| 239 | + matrix.drawRect(1, 1, 2, 2, c); // x0, y0, width, height |
| 240 | + matrix.drawRect(4, 1, 2, 2, c); // x0, y0, width, height |
| 241 | + matrix.drawRect(1, 4, 2, 2, c); // x0, y0, width, height |
| 242 | + matrix.drawRect(4, 4, 2, 2, c); // x0, y0, width, height |
| 243 | + |
| 244 | + //clear out corner pixel of boxes |
| 245 | + matrix.drawPixel(1, 1, 0); // x, y, color |
| 246 | + matrix.drawPixel(5, 1, 0); // x, y, color |
| 247 | + matrix.drawPixel(1, 5, 0); // x, y, color |
| 248 | + matrix.drawPixel(5, 5, 0); // x, y, color |
| 249 | +} |
| 250 | + |
| 251 | +void SnowFlake11(uint32_t c){ |
| 252 | + //corner lines |
| 253 | + matrix.drawLine(0, 2, 2, 0, c); // x0, y0, x1, y1, color |
| 254 | + matrix.drawLine(4, 0, 6, 2, c); // x0, y0, x1, y1, color |
| 255 | + matrix.drawLine(0, 4, 2, 6, c); // x0, y0, x1, y1, color |
| 256 | + matrix.drawLine(4, 6, 6, 4, c); // x0, y0, x1, y1, color |
| 257 | + |
| 258 | + //center X |
| 259 | + matrix.drawLine(2, 2, 4, 4, c); // x0, y0, x1, y1, color |
| 260 | + matrix.drawLine(2, 4, 4, 2, c); // x0, y0, x1, y1, color |
| 261 | + |
| 262 | +} |
| 263 | + |
| 264 | +//8x8 |
| 265 | +void SnowFlake12(uint32_t c){ |
| 266 | + matrix.drawLine(1, 1, 6, 6, c); // x0, y0, x1, y1, color |
| 267 | + matrix.drawLine(1, 6, 6, 1, c); // x0, y0, x1, y1, color |
| 268 | + matrix.fillRect(3, 0, 2, 2, c); // x0, y0, width, height |
| 269 | + matrix.fillRect(0, 3, 2, 2, c); // x0, y0, width, height |
| 270 | + matrix.fillRect(6, 3, 2, 2, c); // x0, y0, width, height |
| 271 | + matrix.fillRect(3, 6, 2, 2, c); // x0, y0, width, height |
| 272 | + matrix.show(); |
| 273 | + |
| 274 | +} |
| 275 | + |
| 276 | +void showAllSnowflakes(uint32_t c){ |
| 277 | + SnowFlake1(matrix.Color(red, green, blue)); |
| 278 | + matrix.show(); // This sends the updated pixel colors to the hardware. |
| 279 | + delay(500); |
| 280 | + matrix.fillScreen(0); |
| 281 | + SnowFlake5(matrix.Color(red, green, blue)); |
| 282 | + matrix.show(); // This sends the updated pixel colors to the hardware. |
| 283 | + delay(500); |
| 284 | + matrix.fillScreen(0); |
| 285 | + SnowFlake2(matrix.Color(red, green, blue)); |
| 286 | + matrix.show(); // This sends the updated pixel colors to the hardware. |
| 287 | + delay(500); |
| 288 | + matrix.fillScreen(0); |
| 289 | + SnowFlake8(matrix.Color(red, green, blue)); |
| 290 | + matrix.show(); // This sends the updated pixel colors to the hardware. |
| 291 | + delay(500); |
| 292 | + matrix.fillScreen(0); |
| 293 | + SnowFlake3(matrix.Color(red, green, blue)); |
| 294 | + matrix.show(); // This sends the updated pixel colors to the hardware. |
| 295 | + delay(500); |
| 296 | + matrix.fillScreen(0); |
| 297 | + SnowFlake9(matrix.Color(red, green, blue)); |
| 298 | + matrix.show(); // This sends the updated pixel colors to the hardware. |
| 299 | + delay(500); |
| 300 | + matrix.fillScreen(0); |
| 301 | + SnowFlake4(matrix.Color(red, green, blue)); |
| 302 | + matrix.show(); // This sends the updated pixel colors to the hardware. |
| 303 | + delay(500); |
| 304 | + matrix.fillScreen(0); |
| 305 | + SnowFlake10(matrix.Color(red, green, blue)); |
| 306 | + matrix.show(); // This sends the updated pixel colors to the hardware. |
| 307 | + delay(500); |
| 308 | + matrix.fillScreen(0); |
| 309 | + SnowFlake6(matrix.Color(red, green, blue)); |
| 310 | + matrix.show(); // This sends the updated pixel colors to the hardware. |
| 311 | + delay(500); |
| 312 | + matrix.fillScreen(0); |
| 313 | + SnowFlake11(matrix.Color(red, green, blue)); |
| 314 | + matrix.show(); // This sends the updated pixel colors to the hardware. |
| 315 | + delay(500); |
| 316 | + matrix.fillScreen(0); |
| 317 | + SnowFlake7(matrix.Color(red, green, blue)); |
| 318 | + matrix.show(); // This sends the updated pixel colors to the hardware. |
| 319 | + delay(500); |
| 320 | + matrix.fillScreen(0); |
| 321 | + SnowFlake11(matrix.Color(red, green, blue)); |
| 322 | + matrix.show(); // This sends the updated pixel colors to the hardware. |
| 323 | + delay(500); |
| 324 | +} |
0 commit comments