/* 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 DATA_PIND 5
#define DATA_PINE 4
#define BRIGHTNESS 255 // Initial brightness (max is 255)
#define NUM_STRIPS 5
#define button 12
int condition = false;
int condition2 = false;
bool mode = false;
byte oldPinState = HIGH;
CRGB ledsA[NUM_LEDS]; // sets number of pixels that will light on each strip.
CRGB ledsB[NUM_LEDS];
CRGB ledsC[NUM_LEDS];
CRGB leds[NUM_STRIPS][NUM_LEDS];
int i = 0;
//*****************************************************
void setup() {
// FastLED.addLeds<WS2812, DATA_PINA, GRB>(ledsA, NUM_LEDS);
// FastLED.addLeds<WS2812, DATA_PINB, GRB>(ledsC, NUM_LEDS);
// FastLED.addLeds<WS2812, DATA_PINC, GRB>(ledsB, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
FastLED.addLeds<WS2812B, DATA_PINA, GRB>(leds[0], NUM_LEDS);
FastLED.addLeds<WS2812B, DATA_PINB, GRB>(leds[1], NUM_LEDS);
FastLED.addLeds<WS2812B, DATA_PINC, GRB>(leds[2], NUM_LEDS);
FastLED.addLeds<WS2812B, DATA_PIND, GRB>(leds[3], NUM_LEDS);
FastLED.addLeds<WS2812B, DATA_PINE, GRB>(leds[4], NUM_LEDS);
pinMode(button, INPUT_PULLUP);
Serial.begin(115200); // Any baud rate should work
Serial.println("Hello Arduino\n");
// FastLED.addLeds<WS2812, LED_PIN_NEW, GRB>(leds[3], NUM_LEDS);
// randomSeed(analogRead(A0)); /*sets the pin to create "static so the the initial LED to light is different
// each time through the loop */
}
//********************************************************
void loop() {
//BlinkRandomly();
byte pinState = digitalRead (button);
if (pinState != oldPinState)
{
delay (10); // debounce
if (pinState == LOW)
if(mode){
mode = false;
}
else{
mode = true;
}
Serial.println(mode);
//digitalWrite (ledPin, !digitalRead (ledPin)); // toggle pin
oldPinState = pinState; // remember new state
// Serial.println(pinState);
} // end of if pin state change
if (mode) {
condition2 = true;
} else {
turnOffAllLEDs();
condition = false;
condition2 = false;
}
// }
// Serial.println(conditionToToggle);
// }
// lastButtonState = buttonState;
// buttonState = digitalRead(button);
// if (buttonState == LOW && i == 0) {
// turnOffAllLEDs();
// condition = false;
// condition2 = true;
// delay(50);
// i++;
// }
// else if (i == 1 && buttonState == LOW) {
// turnOffAllLEDs();
// int condition = false;
// int condition2 = false;
// i = 0;
// }
if (condition2 == true) {
runLEDSequence();
}
if (condition == true) {
static uint8_t brightness = 0;
static bool increasing = true;
// Update brightness
if (increasing) {
brightness++;
if (brightness == 255) {
increasing = false;
}
} else {
brightness--;
if (brightness == 0) {
increasing = true;
}
}
CRGB redColor = CRGB(brightness, brightness, brightness);
for (int i = 0; i < NUM_STRIPS; i++) {
for (int j = 8; j < NUM_LEDS; j++) {
leds[i][j] = redColor;
//delay(2);
}
}
// Show the changes on the LED strip
FastLED.show();
// Adjust the delay to control the speed of the breathing effect
delay(10);
}
//breatheEffect();
// Apply brightness to the LED
// CRGB redColor = CRGB(brightness, 0, 0);
// for (int i = 0; i < NUM_LEDS; i++) {
// ledsA[i] = redColor;
// ledsB[i] = redColor;
// ledsC[i] = redColor;
// }
}
void runLEDSequence() {
// Run LEDs in the new strip one by one
for (int m = 0; m < 2; m++) {
for (int i = 0; i < NUM_LEDS; i++) {
for (int strip = 0; strip < NUM_STRIPS; strip++) {
leds[strip][i] = CRGB(255, 255, 0); // Red color for the active LED in each strip
}
FastLED.show();
delay(50); // Adjust the delay to control the speed of the sequence
// Turn off the active LED in each strip
for (int strip = 0; strip < NUM_STRIPS; strip++) {
leds[strip][i] = CRGB(0, 0, 0);
}
}
}
// m++;
condition = true;
condition2 = false;
// Add a delay before starting the breathing effect
delay(50);
}
void turnOffAllLEDs() {
// Set all LEDs to black (off)
for (int i = 0; i < NUM_STRIPS; i++) {
for (int j = 0; j < NUM_LEDS; j++) {
leds[i][j] = CRGB(0, 0, 0);
}
}
// Show the changes on all LED strips
FastLED.show();
delay(50); // You can adjust this delay if needed
}