Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Adafruit_NeoMatrix example for tiled NeoPixel matrices. Scrolls
- // 'Howdy' across three 10x8 NeoPixel grids that were created using
- // NeoPixel 60 LEDs per meter flex strip.
- #include <Adafruit_GFX.h>
- #include <Adafruit_NeoMatrix.h>
- #include <Adafruit_NeoPixel.h>
- #include <FastLED.h>
- #ifndef PSTR
- #define PSTR // Make Arduino Due happy
- #endif
- #define PIN 6
- // MATRIX DECLARATION:
- // Parameter 1 = width of EACH NEOPIXEL MATRIX (not total display)
- // Parameter 2 = height of each matrix
- // Parameter 3 = number of matrices arranged horizontally
- // Parameter 4 = number of matrices arranged vertically
- // Parameter 5 = pin number (most are valid)
- // Parameter 6 = matrix layout flags, add together as needed:
- // NEO_MATRIX_TOP, NEO_MATRIX_BOTTOM, NEO_MATRIX_LEFT, NEO_MATRIX_RIGHT:
- // Position of the FIRST LED in the FIRST MATRIX; pick two, e.g.
- // NEO_MATRIX_TOP + NEO_MATRIX_LEFT for the top-left corner.
- // NEO_MATRIX_ROWS, NEO_MATRIX_COLUMNS: LEDs WITHIN EACH MATRIX are
- // arranged in horizontal rows or in vertical columns, respectively;
- // pick one or the other.
- // NEO_MATRIX_PROGRESSIVE, NEO_MATRIX_ZIGZAG: all rows/columns WITHIN
- // EACH MATRIX proceed in the same order, or alternate lines reverse
- // direction; pick one.
- // NEO_TILE_TOP, NEO_TILE_BOTTOM, NEO_TILE_LEFT, NEO_TILE_RIGHT:
- // Position of the FIRST MATRIX (tile) in the OVERALL DISPLAY; pick
- // two, e.g. NEO_TILE_TOP + NEO_TILE_LEFT for the top-left corner.
- // NEO_TILE_ROWS, NEO_TILE_COLUMNS: the matrices in the OVERALL DISPLAY
- // are arranged in horizontal rows or in vertical columns, respectively;
- // pick one or the other.
- // NEO_TILE_PROGRESSIVE, NEO_TILE_ZIGZAG: the ROWS/COLUMS OF MATRICES
- // (tiles) in the OVERALL DISPLAY proceed in the same order for every
- // line, or alternate lines reverse direction; pick one. When using
- // zig-zag order, the orientation of the matrices in alternate rows
- // will be rotated 180 degrees (this is normal -- simplifies wiring).
- // See example below for these values in action.
- // Parameter 7 = pixel type flags, add together as needed:
- // NEO_RGB Pixels are wired for RGB bitstream (v1 pixels)
- // NEO_GRB Pixels are wired for GRB bitstream (v2 pixels)
- // NEO_KHZ400 400 KHz bitstream (e.g. FLORA v1 pixels)
- // NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip)
- // Example with three 10x8 matrices (created using NeoPixel flex strip --
- // these grids are not a ready-made product). In this application we'd
- // like to arrange the three matrices side-by-side in a wide display.
- // The first matrix (tile) will be at the left, and the first pixel within
- // that matrix is at the top left. The matrices use zig-zag line ordering.
- // There's only one row here, so it doesn't matter if we declare it in row
- // or column order. The matrices use 800 KHz (v2) pixels that expect GRB
- // color data.
- const int panelWidth = 8;
- const int panelHeight = 8;
- Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(panelWidth, panelHeight, 2, 2, PIN,
- NEO_TILE_TOP + NEO_TILE_LEFT + NEO_TILE_ROWS + NEO_TILE_ZIGZAG +
- NEO_MATRIX_BOTTOM + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG,
- NEO_GRB + NEO_KHZ800);
- const uint8_t kMatrixWidth = 16;
- const uint8_t kMatrixHeight = 16;
- const uint16_t colors[] = {
- matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255)
- };
- void setup() {
- Serial.begin(115200);
- matrix.begin();
- matrix.setTextWrap(false);
- matrix.setBrightness(16);
- matrix.setTextColor(colors[0]);
- }
- int x = matrix.width();
- int pass = 0;
- void loop() {
- DrawCircle();
- DrawSquare(false);
- DrawChar();
- DrawRainbow();
- DrawLove();
- x = 0;
- }
- void DrawCircle() {
- while (x < matrix.width()) {
- matrix.fillScreen(0);
- CRGB color1 = CHSV(0, 0, 255);
- CRGB color2 = CHSV(0, 0, 125);
- CRGB color3 = CHSV(0, 0, 64);
- CRGB color4 = CHSV(0, 0, 8);
- int _x = kMatrixWidth * 0.5;
- int _y = kMatrixHeight * 0.5;
- matrix.drawCircle(_x, _y, x - 3, matrix.Color(color4.red, color4.green, color4.blue));
- matrix.drawCircle(_x, _y, x - 2, matrix.Color(color3.red, color3.green, color3.blue));
- matrix.drawCircle(_x, _y, x - 1, matrix.Color(color2.red, color2.green, color2.blue));
- matrix.drawCircle(_x, _y, x, matrix.Color(color1.red, color1.green, color1.blue));
- matrix.drawCircle(_x, _y, x + 1, matrix.Color(color2.red, color2.green, color2.blue));
- matrix.drawCircle(_x, _y, x + 2, matrix.Color(color3.red, color3.green, color3.blue));
- matrix.drawCircle(_x, _y, x + 3, matrix.Color(color4.red, color4.green, color4.blue));
- matrix.show();
- x++;
- delay(100);
- }
- x = 0;
- }
- void DrawSquare(boolean isFill) {
- while (x < matrix.width()) {
- matrix.fillScreen(0);
- CRGB color1 = CHSV(0, 0, 255);
- CRGB color2 = CHSV(0, 0, 125);
- CRGB color3 = CHSV(0, 0, 64);
- CRGB color4 = CHSV(0, 0, 8);
- int _x = kMatrixWidth * 0.5;
- int _y = kMatrixHeight * 0.5;
- int half = (x / 2.0);
- if (isFill) {
- matrix.fillRect(_x - half, _y - half, x, x, matrix.Color(color1.red, color1.green, color1.blue));
- } else {
- matrix.drawRect(_x - half, _y - half, x, x, matrix.Color(color1.red, color1.green, color1.blue));
- }
- matrix.show();
- x++;
- delay(100);
- }
- x = 0;
- }
- void DrawChar() {
- x = 0;
- matrix.setTextColor(matrix.Color(255, 255, 255));
- matrix.setTextSize(2);
- char message[64] = "01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
- while (x < 63) {
- matrix.fillScreen(0);
- int _x = kMatrixWidth * 0.5;
- int _y = kMatrixHeight * 0.5;
- matrix.setCursor(3, 1);
- matrix.print(String(message[x]));
- x++;
- matrix.show();
- delay(500);
- }
- x = 0;
- }
- void DrawRainbow() {
- x = 0;
- while (x < matrix.width() * 2) {
- uint32_t ms = millis();
- int32_t yHueDelta32 = ((int32_t)cos16( ms * (27 / 1) ) * (350 / kMatrixWidth));
- int32_t xHueDelta32 = ((int32_t)cos16( ms * (39 / 1) ) * (310 / kMatrixHeight));
- DrawOneFrame( ms / 65536, yHueDelta32 / 32768, xHueDelta32 / 32768);
- matrix.show();
- x++;
- delay(50);
- }
- }
- void DrawLove() {
- x = 0;
- matrix.setTextColor(matrix.Color(255, 255, 255));
- matrix.setTextSize(1);
- while (x < matrix.width()) {
- matrix.fillScreen(0);
- int _x = kMatrixWidth * 0.5;
- int _y = kMatrixHeight * 0.5;
- matrix.setCursor(0, 0);
- matrix.print(String("L"));
- matrix.setCursor(8, 0);
- matrix.print(String("O"));
- matrix.setCursor(0, 8);
- matrix.print(String("V"));
- matrix.setCursor(8, 8);
- matrix.print(String("E"));
- x++;
- matrix.show();
- delay(500);
- }
- x = 0;
- }
- void DrawOneFrame( byte startHue8, int8_t yHueDelta8, int8_t xHueDelta8)
- {
- byte lineStartHue = startHue8;
- for ( byte y = 0; y < kMatrixHeight; y++) {
- lineStartHue += yHueDelta8;
- byte pixelHue = lineStartHue;
- for ( byte x = 0; x < kMatrixWidth; x++) {
- pixelHue += xHueDelta8;
- CRGB color = CHSV( pixelHue, 255, 255);
- matrix.drawPixel(x, y, matrix.Color(color.red , color.green, color.blue));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement