Help, lol.
What am I trying to do?
I am trying to run 2 strips of WS2812B leds on pin 4, 72 leds each in parallel so they both run "meteor rain:. 1 WS2812B 60 led ring on pin 5 running "fade in/out" at the same time. I want 2 pull up momentary switches, 1 will trigger both pins to switch to "strobe" for 2 seconds, and the other to switch pin 5 to "running lights"
I have been at this for a few days and am literally cross-eyed. I am still learning and researching everyday and reading through the libraries, although I admit that much of it goes over my head, and this seems like no easy feet. Here is my current attempt to run the sketch. it does compile with no errors, but I think I have changed so many settings attempting to trigger the events i mentioned that I am lost. Please be gentle, and bestow upon me your infinite wisdom's. Seriously, bestow away, lol.
#include "FastLED.h"
// How many leds in your strips?
#define NUM_LEDS_Strips 72
#define NUM_LEDS_Ring 60
// Switches
#define BUTTON_Vibrate 2 // vibration sensor for strobe effect
#define BUTTON_Lever 3 // lever reed switch for chase effect
byte selectedEffect=0;
// Define the array of leds
CRGB ledsStrips[NUM_LEDS_Strips];
CRGB ledsRing[NUM_LEDS_Ring];
void setup() {
FastLED.addLeds<WS2812B, 4, RGB>(ledsStrips, NUM_LEDS_Strips); //LED strips on pin 4 with 72 LEDS
FastLED.addLeds<WS2812B, 5, RGB>(ledsRing, NUM_LEDS_Ring); //LED strips on pin 5 with 60 LEDS
pinMode(BUTTON_Vibrate, INPUT_PULLUP); //Activate internal 40k resistor to +5V;
pinMode(BUTTON_Lever, INPUT_PULLUP); //Activate internal 40k resistor to +5V;
attachInterrupt(digitalPinToInterrupt(BUTTON_Vibrate), Strobe, CHANGE); // pressed
attachInterrupt(digitalPinToInterrupt(BUTTON_Lever), RunningLights, CHANGE); // pressed
}
void loop() {
switch(selectedEffect) {
case 0 : {
// Strobe - Color (red, green, blue), number of flashes, flash speed, end pause
Strobe(0xff, 0xff, 0xff, 10, 50, 1000);
delay (2000);
break;
}
case 1 : {
// Running Lights - Color (red, green, blue), wave dealy
// RunningLights(0xff,0x00,0x00, 50); // red
// RunningLights(0xff,0xff,0xff, 50); // white
RunningLights(0x00,0x00,0xff, 50); // blue
delay (2000);
break;
}
default : {
// meteorRain - Color (red, green, blue), meteor size, trail decay, random trail decay (true/false), speed delay
meteorRain(0xff,0xff,0xff,10, 64, true, 30);
// FadeInOut - Color (red, green. blue)
// FadeInOut(0xff, 0x00, 0x00); // red
// FadeInOut(0xff, 0xff, 0xff); // white
FadeInOut(0x00, 0x00, 0xff); // blue
break;
}
}
}
// *************************
// ** LEDEffect Functions **
// *************************
void FadeInOut(byte red, byte green, byte blue){
float r, g, b;
for(int k = 0; k < 256; k=k+1) {
r = (k/256.0)*red;
g = (k/256.0)*green;
b = (k/256.0)*blue;
setAll_Ring(r,g,b);
showStrip_2();
}
for(int k = 255; k >= 0; k=k-2) {
r = (k/256.0)*red;
g = (k/256.0)*green;
b = (k/256.0)*blue;
setAll_Ring(r,g,b);
showStrip_2();
}
}
void Strobe(byte red, byte green, byte blue, int StrobeCount, int FlashDelay, int EndPause){
for(int j = 0; j < StrobeCount; j++) {
setAll_Ring(red,green,blue);
showStrip_1();
showStrip_2();
delay(FlashDelay);
setAll_Ring(0,0,0);
showStrip_1();
showStrip_2();
delay(FlashDelay);
}
delay(EndPause);
}
void RunningLights(byte red, byte green, byte blue, int WaveDelay) {
int Position=0;
for(int i=0; i<NUM_LEDS_Ring*2; i++)
{
Position++; // = 0; //Position + Rate;
for(int i=0; i<NUM_LEDS_Ring; i++) {
// sine wave, 3 offset waves make a rainbow!
//float level = sin(i+Position) * 127 + 128;
//setPixel(i,level,0,0);
//float level = sin(i+Position) * 127 + 128;
setPixel(i,((sin(i+Position) * 127 + 128)/255)*red,
((sin(i+Position) * 127 + 128)/255)*green,
((sin(i+Position) * 127 + 128)/255)*blue);
}
showStrip_2();
delay(WaveDelay);
}
}
void theaterChase(byte red, byte green, byte blue, int SpeedDelay) {
for (int j=0; j<10; j++) { //do 10 cycles of chasing
for (int q=0; q < 3; q++) {
for (int i=0; i < NUM_LEDS_Ring; i=i+3) {
setPixel(i+q, red, green, blue); //turn every third pixel on
}
showStrip_2();
delay(SpeedDelay);
for (int i=0; i < NUM_LEDS_Ring; i=i+3) {
setPixel(i+q, 0,0,0); //turn every third pixel off
}
}
}
}
void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {
setAll_Strips(0,0,0);
for(int i = 0; i < NUM_LEDS_Strips+NUM_LEDS_Strips; i++) {
// fade brightness all LEDs one step
for(int j=0; j<NUM_LEDS_Strips; j++) {
if( (!meteorRandomDecay) || (random(10)>5) ) {
fadeToBlack(j, meteorTrailDecay );
}
}
// draw meteor
for(int j = 0; j < meteorSize; j++) {
if( ( i-j <NUM_LEDS_Strips) && (i-j>=0) ) {
setPixel(i-j, red, green, blue);
}
}
showStrip_1();
delay(SpeedDelay);
}
}
// used by meteorrain
void fadeToBlack(int ledNo, byte fadeValue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
uint32_t oldColor;
uint8_t r, g, b;
int value;
oldColor = strip.getPixelColor(ledNo);
r = (oldColor & 0x00ff0000UL) >> 16;
g = (oldColor & 0x0000ff00UL) >> 8;
b = (oldColor & 0x000000ffUL);
r=(r<=10)? 0 : (int) r-(r*fadeValue/256);
g=(g<=10)? 0 : (int) g-(g*fadeValue/256);
b=(b<=10)? 0 : (int) b-(b*fadeValue/256);
strip.setPixelColor(ledNo, r,g,b);
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
ledsStrips[ledNo].fadeToBlackBy( fadeValue );
#endif
}
// ***************************************
// ** FastLed/NeoPixel Common Functions **
// ***************************************
// Apply LED color changes to Strips
void showStrip_1() {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.show();
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
FastLED[0].showLeds();
#endif
}
// Apply LED color changes to Ring
void showStrip_2() {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.show();
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
FastLED[1].showLeds();
#endif
}
// Set a LED color (not yet visible)
void setPixel(int Pixel, byte red, byte green, byte blue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
ledsStrips[Pixel].r = red;
ledsStrips[Pixel].g = green;
ledsStrips[Pixel].b = blue;
ledsRing[Pixel].r = red;
ledsRing[Pixel].g = green;
ledsRing[Pixel].b = blue;
#endif
}
// Set all LEDs to a given color and apply it (visible)
void setAll_Strips(byte red, byte green, byte blue) {
for(int i = 0; i < NUM_LEDS_Strips; i++ ) {
setPixel(i, red, green, blue);
}
showStrip_1();
}
// Set all LEDs to a given color and apply it (visible)
void setAll_Ring(byte red, byte green, byte blue) {
for(int i = 0; i < NUM_LEDS_Ring; i++ ) {
setPixel(i, red, green, blue);
}
showStrip_2();
}