hi,
i have a simple idea that is working, and i want it to work better!
trigger switch at the bottom of the stairs, and another at the top.
2 lights in the ceiling, 14 lights up the stairs and then 3 lights at the landing.
the premise is easy, trip the bottom switch and the ceiling lights turn on, then the steps in order going up, and then the landing lights go on, they stay on for 25 seconds and then fade out in order.
i have a dial at the bottom of the stairs, with 10 presets for colours
now my issue, is that when i have started the process, it goes through the process fine, but there is no possibility for interaction until the system has completed.
if i change the colour whilst the lights are on, it will be ignored until it has all faded out and waiting to restart.
i know that its getting stuck in the for loops for the fade ins and fade outs, but how to reorganise the code so if i change the dial mid step, the colours change.
thanks!
// SAVED FOR POSTERITY
// for(int i=0;i<NUM_LEDS;i++) {
// leds[i].nscale8(200);
// }
#include "FastLED.h"
#define NUM_LEDS 19 // 20
#define DATA_PIN 3 // 3
//#define CLOCK_PIN 13 // 13 (lpd8806)
CRGB leds[NUM_LEDS];
// user variables
int stairsontime = 500; // 25000
int interimtime = 500; // 500
int accentdecay = 2; // 20
int landingdecay = 1; // 10
int stairlightuptime = 100; // 100
int bright = 32; // 255
// ACCENT COLOUR VARIABLES
int ahue;
int asat = 255;
int avol = 255;
// STAIR COLOUR VARIABLES
int bhue = 160;
int bsat = 255;
int bvol = 255;
// LANDING COLOUR VARIABLES
int chue = 160;
int csat = 255;
int cvol = 255;
int bottombutton = 5;
int topbutton = 6;
int patterndial = 21;
int whichbutton = 0; // DEFAULT IS 0
volatile int bottombuttonstate = LOW;
volatile int topbuttonstate = LOW;
volatile int patternstate;
//int val = 2;
int val = analogRead(patterndial);
int huev = map(val, 0, 1023, 0, 255);
int pattern = 0;//map(val, 5, 811, 0, 10); // 10 SETTINGS FOR POTENTIOMETER
void setup() {
Serial.begin(38400);
delay(2000);
LEDS.setBrightness(bright);
FastLED.addLeds<WS2811, DATA_PIN, RBG>(leds, NUM_LEDS);
//FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, BRG>(leds, NUM_LEDS);
//set up the buttons
pinMode(bottombutton, INPUT_PULLUP);
pinMode(topbutton, INPUT_PULLUP);
pinMode(patterndial, INPUT);
//Attach the interrupt to the input pin and monitor for ANY Change
attachInterrupt(bottombutton, bottomchange, CHANGE);
attachInterrupt(topbutton, topchange, CHANGE);
attachInterrupt(patterndial, patternchange, CHANGE);
// clear the leds
memset(leds, 0, NUM_LEDS * sizeof(struct CRGB));
}
void loop() {
Serial.println("program running");
switch (whichbutton) {
case 1: // bottom step
// ACCENT LIGHTING
for (int i = 0; i < 255; i++) {
leds[0] = CHSV(ahue, asat, i);
leds[1] = CHSV(ahue, asat, i);
LEDS.setBrightness(bright);
FastLED.show();
}
// UP LIGHTING
for (int i=2; i < 15; i++) {
for (int fade = 0; fade < 255; fade++) {
leds[i] = CHSV( bhue, bsat, fade);
FastLED.show();
}
delay(stairlightuptime);
}
// LANDING LIGHTING
for (int k = 0; k < 255; k++) {
for (int j = 15; j < NUM_LEDS; j++) {
leds[j] = CHSV(chue, csat, k);
LEDS.setBrightness(bright);
FastLED.show();
}
}
whichbutton = 3;
delay(stairsontime);
break;
case 2: // top step
// LANDING LIGHTING
for (int k = 0; k < 255; k++) {
for (int j = 15; j < NUM_LEDS; j++) {
leds[j] = CHSV(chue, csat, k);
LEDS.setBrightness(bright);
FastLED.show();
}
}
// ACCENT LIGHTING
for (int i = 0; i < 255; i++) {
leds[0] = CHSV(ahue, asat, i);
leds[1] = CHSV(ahue, asat, i);
LEDS.setBrightness(bright);
FastLED.show();
}
// DOWN LIGHTING
for (int i=14; i > 1; i--) {
for (int fade = 0; fade < 255; fade++) {
leds[i] = CHSV( bhue, bsat, fade);
FastLED.show();
}
delay(stairlightuptime);
}
whichbutton = 3;
delay(stairsontime);
break;
case 3: // all off
// END OF LIGHT
// STEPS
for (int fade = 255; 0 < fade; fade--) {
for (int i=2; i < 15; i++) {
leds[i] = CHSV( bhue, bsat, fade);
FastLED.show();
}
}
delay(interimtime); // delay between steps and landing
for (int fade = 255; 0 < fade; fade--) {
for (int i=15; i < NUM_LEDS; i++) {
leds[i] = CHSV( chue, csat, fade);
FastLED.show();
delay(landingdecay); // speed of fade
}
}
delay(interimtime); // delay between landing and accent
for (int fade = 255; 0 < fade; fade--) {
for (int i=0; i < 2; i++) {
leds[i] = CHSV( ahue, asat, fade);
FastLED.show();
delay(accentdecay); // speed of fade
}
whichbutton = 0;
}
break;
default:
for (int i=0; i < NUM_LEDS; i++) {
leds[i] = CHSV( 0, 0, 0);
FastLED.show();
}
} // end of switch
} // end of void loop
void bottomchange() {
bottombuttonstate = !bottombuttonstate;
patternchange();
whichbutton = 1;
}
void topchange() {
topbuttonstate = !topbuttonstate;
patternchange();
whichbutton = 2;
}
void patternchange() {
Serial.println(pattern);
val = analogRead(patterndial);
pattern = map(val, 0, 1023, 0, 10);
if (pattern == 1) {
ahue = 0;
bhue = 0;
chue = 0;
}
if (pattern == 2) {
ahue = 16;
bhue = 16;
chue = 16;
}
if (pattern == 3) {
ahue = 32;
bhue = 32;
chue = 32;
}
if (pattern == 4) {
ahue = 48;
bhue = 48;
chue = 48;
}
if (pattern == 5) {
ahue = 64;
bhue = 64;
chue = 64;
}
if (pattern == 6) {
ahue = 80;
bhue = 80;
chue = 80;
}
if (pattern == 7) {
ahue = 96;
bhue = 96;
chue = 96;
}
if (pattern == 8) {
ahue = 112;
bhue = 112;
chue = 112;
}
if (pattern == 9) {
ahue = 128;
bhue = 128;
chue = 128;
}
if (pattern == 10) {
ahue = 160;
bhue = 160;
chue = 160;
}
}