/* flash 3 Pixel LED strips randomly version 2
www. steamtraininfo.com.
This sketch uses 3
WS2812B pixel strips.
*/
#include <FastLED.h>
#define NUM_LEDS 15 /*the number of leds that will light. If */
//****************************
#define DATA_PINA 8 // Connect to the data wires on the pixel strips
#define DATA_PINB 7
#define DATA_PINC 6
//***********************************************************
#define Switch_A 2 // will switch strips on and off
#define Switch_B 3
#define Switch_C 4
//*************************************
int val_A = 0; // declares and sets initial values of val
int val_B = 0;
int val_C = 0;
int randNumber; // from random sketch
CRGB ledsA[NUM_LEDS]; // sets number of pixels that will light on each strip.
CRGB ledsB[NUM_LEDS];
CRGB ledsC[NUM_LEDS];
//*****************************************************
void setup() {
FastLED.addLeds<WS2812B, DATA_PINA, GRB>(ledsA, NUM_LEDS); //
FastLED.addLeds<WS2812B, DATA_PINB, GRB>(ledsB, NUM_LEDS);
FastLED.addLeds<WS2812B, DATA_PINC, GRB>(ledsC, NUM_LEDS);
//*************************************
pinMode(Switch_A, INPUT); //establishes how pin processes data
pinMode(Switch_A, INPUT);
pinMode(Switch_A, INPUT);
/* This sets 3 leds on pins D2 to D4 to output
*/
for (int i = 2; i <= 4; i++) {
pinMode(i, OUTPUT); // sets pins to output
}
randomSeed(analogRead(A0)); /*sets the pin to create "static so the the initial LED to light is different
eacg time through the loop */
}
//********************************************************
void loop() {
BlinkRandomly();
StripA();
StripB();
StripC();
}
//Functions
//***********************************************
void StripA()
{
EVERY_N_MILLIS(1000) {
val_A = !val_A;
if (val_A) {
fill_solid(ledsA, NUM_LEDS, CRGB::Red);
} else {
fill_solid(ledsA, NUM_LEDS, CRGB::Black);
}
FastLED.show();
};
}
void StripB()
{
EVERY_N_MILLIS(1000) {
val_B = !val_B;
if (val_B) {
fill_solid(ledsB, NUM_LEDS, CRGB::Red);
} else {
fill_solid(ledsB, NUM_LEDS, CRGB::Black);
}
FastLED.show();
};
}
//*******************************************************
void StripC()
{
EVERY_N_MILLIS(1000) {
val_C = !val_C;
if (val_C) {
fill_solid(ledsC, NUM_LEDS, CRGB::Red);
} else {
fill_solid(ledsC, NUM_LEDS, CRGB::Black);
}
FastLED.show();
};
}
//**************************************************
void BlinkRandomly() {
randNumber= random(25, 200);
int LightLED = random(2, 5); //randomly selects LED to light. Must use +1 over the last pin number
//(ie: 4 + 1 = 5)
int dlay = randNumber; // sets the blink rate in milliseconds
digitalWrite(LightLED, HIGH);
delay(dlay);
digitalWrite(LightLED, LOW);
delay(dlay);
}