// https://forum.arduino.cc/t/has-anyone-ever-tried-making-emergency-lights-with-2-independent-neopixel-matrix-4x4-tiles/1267869/
// red blue... red blue... blue blue... red red... white white...
#include <FastLED.h>
#define buttonPin 2
#define pixelPin 12
#define NUM_PIX 4 * 4 * 2 // number of NeoPixels
CRGB led[NUM_PIX];
byte maxBright = 255;
int wait = 250, strobe = 4; // time between on and off
unsigned long lastButtonRead, timer, debounceTimeout; // timers for button reading
bool currentButtonState, currentButtonRead; // states for button reading
void setup() {
Serial.begin(115200);
// configure pins
pinMode (pixelPin, OUTPUT); // Neopixel data pin
pinMode (buttonPin, INPUT_PULLUP); // Neopixel data pin
// configure FastLED
FastLED.addLeds<WS2812B, pixelPin, GRB>(led, NUM_PIX); // led = object, NUM_PIX = total Pixels
FastLED.setBrightness(maxBright); // limit the brightness of each pixel to this value
FastLED.clear(); // clear the buffer
FastLED.show(); // display the buffer
while (digitalRead(buttonPin)); // hold program here until button is pressed
}
void loop() {
// use functions for a modular sketch
redblu(2);
blublk(2);
redblu(2);
redred(2);
whtwht(4);
}
void redblu(int r) {
for (int i = 0; i < r; i++) {
fill_solid(led, NUM_PIX, CRGB::Red);
fill_solid(led, NUM_PIX / 2, CRGB::Blue);
FastLED.show();
delay(wait);
fill_solid(led, NUM_PIX, CRGB::Blue);
fill_solid(led, NUM_PIX / 2, CRGB::Red);
FastLED.show();
delay(wait);
}
}
void blublk(int r) {
for (int i = 0; i < r; i++) {
fill_solid(led, NUM_PIX, CRGB::Black);
fill_solid(led, NUM_PIX / 2, CRGB::Blue);
FastLED.show();
delay(wait);
fill_solid(led, NUM_PIX, CRGB::Blue);
fill_solid(led, NUM_PIX / 2, CRGB::Black);
FastLED.show();
delay(wait);
}
}
void redred(int r) {
for (int i = 0; i < r; i++) {
fill_solid(led, NUM_PIX, CRGB::Red);
fill_solid(led, NUM_PIX / 2, CRGB::Black);
FastLED.show();
delay(wait);
fill_solid(led, NUM_PIX, CRGB::Black);
fill_solid(led, NUM_PIX / 2, CRGB::Red);
FastLED.show();
delay(wait);
}
}
void whtwht(int r) {
for (int i = 0; i < r; i++) {
fill_solid(led, NUM_PIX, CRGB::White);
fill_solid(led, NUM_PIX / 2, CRGB::Black);
FastLED.show();
delay(wait / strobe);
FastLED.clear();
FastLED.show();
delay(wait / strobe);
fill_solid(led, NUM_PIX, CRGB::White);
fill_solid(led, NUM_PIX / 2, CRGB::Black);
FastLED.show();
delay(wait);
fill_solid(led, NUM_PIX, CRGB::Black);
fill_solid(led, NUM_PIX / 2, CRGB::White);
FastLED.show();
delay(wait / strobe);
FastLED.clear();
FastLED.show();
delay(wait / strobe);
fill_solid(led, NUM_PIX, CRGB::Black);
fill_solid(led, NUM_PIX / 2, CRGB::White);
FastLED.show();
delay(wait);
}
}START