#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#include <WS2812FX.h>
#define PIN 5
#define SETA_ESQUERDA 13
#define QTDE_COLUNAS 32
#define QTDE_LINHAS 8
#define QTDE_PIXELS QTDE_COLUNAS *QTDE_LINHAS *QTDE_MATRIZES_HORI *QTDE_MATRIZES_VERT
#define QTDE_MATRIZES_HORI 2
#define QTDE_MATRIZES_VERT 1
// MATRIX DECLARATION:
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(QTDE_COLUNAS, QTDE_LINHAS, QTDE_MATRIZES_HORI, QTDE_MATRIZES_VERT, PIN,
NEO_TILE_TOP + NEO_TILE_LEFT + NEO_TILE_ROWS + NEO_TILE_PROGRESSIVE + NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG,
NEO_GRB + NEO_KHZ800);
// 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.
// STRIP DECLARATION:
// Adafruit_NeoPixel strip(QTDE_PIXELS, PIN, NEO_GRB + NEO_KHZ800);
WS2812FX ws2812fx = WS2812FX(QTDE_PIXELS, PIN, NEO_GRB + NEO_KHZ800);
// Argument 1 = Number of pixels in NeoPixel strip
// Argument 2 = Arduino pin number (most are valid)
// Argument 3 = Pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
void setup()
{
/* Configura o GPIO do botão como entrada
e configura interrupção externa no modo
RISING para ele.
*/
pinMode(SETA_ESQUERDA, INPUT);
attachInterrupt(SETA_ESQUERDA, setaLadoEsquerdo, RISING);
iniciarLibWS2812FX();
}
void loop()
{
lanternasPadrao();
}
void iniciarLibWS2812FX()
{
ws2812fx.init();
ws2812fx.setBrightness(255);
// ws2812fx.setSpeed(200);
// ws2812fx.setMode(FX_MODE_RAINBOW_CYCLE);
ws2812fx.start();
}
void lanternasPadrao()
{
ws2812fx.setSegment(0, (QTDE_PIXELS / 8), ((QTDE_PIXELS / 8) * 3) - 1, FX_MODE_STATIC, RED, 1000);
ws2812fx.setSegment(1, (QTDE_PIXELS / 8) * 5, ((QTDE_PIXELS / 8) * 7) - 1, FX_MODE_STATIC, RED, 1000, REVERSE);
ws2812fx.service();
}
void setaLadoEsquerdo()
{
ws2812fx.setSegment(0, 0, (QTDE_PIXELS / 8), FX_MODE_STATIC, BLUE, 1000);
ws2812fx.setSegment(1, (QTDE_PIXELS / 8), ((QTDE_PIXELS / 8) * 3) - 1, FX_MODE_STATIC, RED, 1000);
ws2812fx.setSegment(2, (QTDE_PIXELS / 8) * 5, ((QTDE_PIXELS / 8) * 7) - 1, FX_MODE_STATIC, RED, 1000, REVERSE);
ws2812fx.service();
delay(10000);
}
void aplicarEfeitoFXNas2LanternasSeparadamente(uint8_t efeito)
{
/*
// setSegment(segment index, start LED, stop LED, mode, color, speed, reverse);
#define FX_MODE_STATIC 0
#define FX_MODE_BLINK 1
#define FX_MODE_BREATH 2
#define FX_MODE_COLOR_WIPE 3
#define FX_MODE_COLOR_WIPE_INV 4
#define FX_MODE_COLOR_WIPE_REV 5
#define FX_MODE_COLOR_WIPE_REV_INV 6
#define FX_MODE_COLOR_WIPE_RANDOM 7
#define FX_MODE_RANDOM_COLOR 8
#define FX_MODE_SINGLE_DYNAMIC 9
#define FX_MODE_MULTI_DYNAMIC 10
#define FX_MODE_RAINBOW 11
#define FX_MODE_RAINBOW_CYCLE 12
#define FX_MODE_SCAN 13
#define FX_MODE_DUAL_SCAN 14
#define FX_MODE_FADE 15
#define FX_MODE_THEATER_CHASE 16
#define FX_MODE_THEATER_CHASE_RAINBOW 17
#define FX_MODE_RUNNING_LIGHTS 18
#define FX_MODE_TWINKLE 19
#define FX_MODE_TWINKLE_RANDOM 20
#define FX_MODE_TWINKLE_FADE 21
#define FX_MODE_TWINKLE_FADE_RANDOM 22
#define FX_MODE_SPARKLE 23
#define FX_MODE_FLASH_SPARKLE 24
#define FX_MODE_HYPER_SPARKLE 25
#define FX_MODE_STROBE 26
#define FX_MODE_STROBE_RAINBOW 27
#define FX_MODE_MULTI_STROBE 28
#define FX_MODE_BLINK_RAINBOW 29
#define FX_MODE_CHASE_WHITE 30
#define FX_MODE_CHASE_COLOR 31
#define FX_MODE_CHASE_RANDOM 32
#define FX_MODE_CHASE_RAINBOW 33
#define FX_MODE_CHASE_FLASH 34
#define FX_MODE_CHASE_FLASH_RANDOM 35
#define FX_MODE_CHASE_RAINBOW_WHITE 36
#define FX_MODE_CHASE_BLACKOUT 37
#define FX_MODE_CHASE_BLACKOUT_RAINBOW 38
#define FX_MODE_COLOR_SWEEP_RANDOM 39
#define FX_MODE_RUNNING_COLOR 40
#define FX_MODE_RUNNING_RED_BLUE 41
#define FX_MODE_RUNNING_RANDOM 42
#define FX_MODE_LARSON_SCANNER 43
#define FX_MODE_COMET 44
#define FX_MODE_FIREWORKS 45
#define FX_MODE_FIREWORKS_RANDOM 46
#define FX_MODE_MERRY_CHRISTMAS 47
#define FX_MODE_FIRE_FLICKER 48
#define FX_MODE_FIRE_FLICKER_SOFT 49
#define FX_MODE_FIRE_FLICKER_INTENSE 50
#define FX_MODE_CIRCUS_COMBUSTUS 51
#define FX_MODE_HALLOWEEN 52
#define FX_MODE_BICOLOR_CHASE 53
#define FX_MODE_TRICOLOR_CHASE 54
#define FX_MODE_TWINKLEFOX 55
#define FX_MODE_RAIN 56
#define FX_MODE_CUSTOM 57 // keep this for backward compatiblity
#define FX_MODE_CUSTOM_0 57 // custom modes need to go at the end
#define FX_MODE_CUSTOM_1 58
#define FX_MODE_CUSTOM_2 59
#define FX_MODE_CUSTOM_3 60
#define FX_MODE_CUSTOM_4 61
#define FX_MODE_CUSTOM_5 62
#define FX_MODE_CUSTOM_6 63
#define FX_MODE_CUSTOM_7 64
*/
ws2812fx.setSegment(0, 0, (QTDE_PIXELS / 2) - 1, efeito, 1000, false);
ws2812fx.setSegment(1, QTDE_PIXELS / 2, QTDE_PIXELS - 1, efeito, 1000, true);
ws2812fx.service();
}
// --------------- MATRIX -----------------
int x = matrix.width();
int pass = 0;
const uint16_t colors[] = {
matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255)};
void iniciarMatrix()
{
matrix.begin();
matrix.setTextWrap(false);
matrix.setBrightness(255);
matrix.setTextColor(colors[0]);
}
void aplicarTextoMatrix(String texto, uint8_t wait)
{
matrix.fillScreen(0);
matrix.setCursor(x, 0);
matrix.print(texto);
if (--x < -85)
{
x = matrix.width();
if (++pass >= 3)
pass = 0;
matrix.setTextColor(colors[pass]);
}
matrix.show();
delay(wait);
}