#include <FastLED.h>
// DEFINE LED Parameters
#define NUM_PANELS 3
#define NUM_LEDS 3 // The number of LEDs you are controlling on the LED Strip. Acceptable values are 1 - 255
#define BRIGHTNESS 175 // values 0-255 the bigger the brighter
#define LED_TYPE NEOPIXEL // Type of LEDs to control
#define LEDPIN0 4
#define LEDPIN1 5
#define LEDPIN2 6
// Order of the LED Colors.
#define COLOR_ORDER BRG
// Array of LEDs
CRGB leds[NUM_PANELS][NUM_LEDS];
int onoffState[NUM_PANELS] = {0, 0, 0}; // Track the state of the lights. 0 = Off, 1 = On
int count = 0;
// method to turn the LEDs Off
void turnOffLEDS(int panelIndex){
Serial.println("Turn Off the Lights");
onoffState[panelIndex] = 0;
for( int i = 0; i < NUM_LEDS; ++i) {
leds[panelIndex][i] = CRGB::Black;
}
FastLED.show();
}
// method to turn the LEDs On
void turnOnLEDS(int panelIndex){
Serial.println("Turn On the Lights");
onoffState[panelIndex] = 1;
for( int i = 0; i < NUM_LEDS; ++i) {
leds[panelIndex][i] = CRGB::AntiqueWhite ;
}
FastLED.show();
}
void setup(){
Serial.begin(115200);
delay( 3000 ); // power-up safety delay
Serial.println("Begin Setup");
// Serial.print("DCC Decoder Addresses: ");
// Serial.print(DCC_ADDRESS0);
// Serial.print(", ");
// Serial.println(DCC_ADDRESS1);
// set up output pin 4
FastLED.addLeds<NEOPIXEL, LEDPIN0>(leds[0], NUM_LEDS);
FastLED.addLeds<NEOPIXEL, LEDPIN1>(leds[1], NUM_LEDS);
FastLED.addLeds<NEOPIXEL, LEDPIN2>(leds[2], NUM_LEDS);
FastLED.setBrightness( BRIGHTNESS );
uint8_t maxWaitLoops = 255;
while(!Serial && maxWaitLoops--)
delay(20);
// Call the main DCC Init function to enable the DCC Receiver
// Dcc.init( MAN_ID_DIY, 10, CV29_ACCESSORY_DECODER | CV29_OUTPUT_ADDRESS_MODE, 0 );
for( int i = 0; i < NUM_PANELS; ++i) {
onoffState[i] = 1;
processLEDState[i];
}
delay(3000);
for( int i = 0; i < NUM_PANELS; ++i) {
onoffState[i] = 0;
processLEDState[i];
}
Serial.println("Setup Finished");
}
void processLEDState(int panelIndex){
if( onoffState[panelIndex] == 1 ){
turnOnLEDS(panelIndex);
} else if (onoffState[panelIndex] == 0){
turnOffLEDS(panelIndex);
}
}
void loop(){
switch( count)
{
case 0:
fill_solid(leds[0], NUM_LEDS, CRGB::MidnightBlue);
fill_solid(leds[1], NUM_LEDS, CRGB::Orchid);
fill_solid(leds[2], NUM_LEDS, CRGB::Orange);
break;
case 1:
fill_solid(leds[0], NUM_LEDS, CRGB::Orange);
fill_solid(leds[1], NUM_LEDS, CRGB::MidnightBlue);
fill_solid(leds[2], NUM_LEDS, CRGB::Orchid);
break;
case 2:
fill_solid(leds[0], NUM_LEDS, CRGB::Orchid);
fill_solid(leds[1], NUM_LEDS, CRGB::Orange);
fill_solid(leds[2], NUM_LEDS, CRGB::MidnightBlue);
break;
case 3:
// Random for every pixel
for( int i=0; i<NUM_LEDS; i++)
{
leds[0][i].r = random( 0, 256);
leds[0][i].g = random( 0, 256);
leds[0][i].b = random( 0, 256);
leds[1][i].r = random( 0, 256);
leds[1][i].g = random( 0, 256);
leds[1][i].b = random( 0, 256);
leds[2][i].r = random( 0, 256);
leds[2][i].g = random( 0, 256);
leds[2][i].b = random( 0, 256);
}
break;
}
count++;
if( count > 3)
count = 0;
FastLED.show();
delay(700);
}