fade timing issue

I am using arduino to control a LED painter II from brilldea.com. I have wired 6 pushbuttons via digital input and have this functioning correctly, each channel will either light up or go off when the button is pressed relative to whether the input is set for HIGH or LOW. the problem I am having is the speed at which the LED’s are fading between colors. I would like to slow the fade speed down, but if I slow the delay down then it will not register every pushbutton being pressed. Im thinking I need to somehow run the fade differently but I dont know how, Ive only been using arduino for a week or so.

any advice is greatly appreciated. here is the code:

// Fade between two colors at specified interval
void fadeall(int rate, int fromred, int fromgreen, int fromblue, int tored, int togreen, int toblue) {

for (int i = 0; i < 33; i++){ //i have tried changing the 33 to a higher number but it causes a lot of flickering in the LED’s
// when I do so
snState = digitalRead(snPin);
toState = digitalRead(toPin);
ttoState = digitalRead(ttoPin);
tttoState = digitalRead(tttoPin);
baState = digitalRead(baPin);
basState = digitalRead(basPin);

if (snState == LOW) {
LEDChannels[0][0] = (fromred * (32 - i) + tored * i)/32;
LEDChannels[0][1] = (fromgreen * (32 - i) + togreen * i)/32;
LEDChannels[0][2] = (fromblue * (32 - i) + toblue * i)/32;}
else {
LEDChannels[0][0] = 0;
LEDChannels[0][1] = 0;
LEDChannels[0][2] = 0;}

if (toState == HIGH){
LEDChannels[1][0] = (fromred * (32 - i) + tored * i)/32;
LEDChannels[1][1] = (fromgreen * (32 - i) + togreen * i)/32;
LEDChannels[1][2] = (fromblue * (32 - i) + toblue * i)/32;}
else {
LEDChannels[1][0] = 0;
LEDChannels[1][1] = 0;
LEDChannels[1][2] = 0;}

if (ttoState == HIGH){
LEDChannels[2][0] = (fromred * (32 - i) + tored * i)/32;
LEDChannels[2][1] = (fromgreen * (32 - i) + togreen * i)/32;
LEDChannels[2][2] = (fromblue * (32 - i) + toblue * i)/32;}
else {
LEDChannels[2][0] = 0;
LEDChannels[2][1] = 0;
LEDChannels[2][2] = 0;}

if (tttoState == HIGH){
LEDChannels[3][0] = (fromred * (32 - i) + tored * i)/32;
LEDChannels[3][1] = (fromgreen * (32 - i) + togreen * i)/32;
LEDChannels[3][2] = (fromblue * (32 - i) + toblue * i)/32;}
else {
LEDChannels[3][0] = 0;
LEDChannels[3][1] = 0;
LEDChannels[3][2] = 0;}

if (baState == HIGH){
LEDChannels[4][0] = (fromred * (32 - i) + tored * i)/32;
LEDChannels[4][1] = (fromgreen * (32 - i) + togreen * i)/32;
LEDChannels[4][2] = (fromblue * (32 - i) + toblue * i)/32;}
else{
LEDChannels[4][0] = 0;
LEDChannels[4][1] = 0;
LEDChannels[4][2] = 0;}

if (basState == HIGH){
LEDChannels[5][0] = (fromred * (32 - i) + tored * i)/32;
LEDChannels[5][1] = (fromgreen * (32 - i) + togreen * i)/32;
LEDChannels[5][2] = (fromblue * (32 - i) + toblue * i)/32;}
else {
LEDChannels[5][0] = 0;
LEDChannels[5][1] = 0;
LEDChannels[5][2] = 0;}
WriteLEDArray();
delay(10); // <---- this is the delay that I have adjusted, at this setting it will register the fastest of
//push’s on the buttons, but the fade is very fast, raising the delay gets me the slower fade,
// but it wont register every pushbutton if they are fast

}}

void loop() {

fadeall(1023,0,0,0,1023,0,0);
fadeall(1023,1023,0,0,0,0,0);

delay(10);
}

You should look at the blink without delay example. Basically what you want to do is, on every pass through loop, check the status of the buttons, an then see if it is time to change the value being written to the leds. If it is, change the value, and record the time that the change occurred.

I am having a hard time figuring out how to adapt this code to the blinkwithout delay tutorial. I had tried previously with that example. Maybe I am doing this wrong with adressing the output, I have changed the sample code that i found because I did not know how to get it to work the original way it was written. Here is how it was written:

// Fade between two colors at specified interval
void fadeall(int rate, int fromred, int fromgreen, int fromblue, int tored, int togreen, int toblue) {

for (int i = 0; i < 33; i++) {

for (int j1 = 0; j1 < NumLEDs; j1++) {
LEDChannels[j1][0] = (fromred * (32 - i) + tored * i)/32;
LEDChannels[j1][1] = (fromgreen * (32 - i) + togreen * i)/32;
LEDChannels[j1][2] = (fromblue * (32 - i) + toblue * i)/32;
}

WriteLEDArray();
delay(15);

}
}

void loop() {
fadeall(1023,0,0,0,0,0,1023);
fadeall(1023,0,0,1023,0,0,0);
}

using the code this way it cycles the fade continuously on all LED channels. I cant figure out how to assign the current value of each RGB led to an integer, and then call that when the button is pressed, like I have this in mind just dont know how to do it:

// Fade between two colors at specified interval
void fadeall(int rate, int fromred, int fromgreen, int fromblue, int tored, int togreen, int toblue) {

for (int i = 0; i < 33; i++) {

for (int j1 = 0; j1 < NumLEDs; j1++) {
LEDChannels[j1][0] = (fromred * (32 - i) + tored * i)/32;
LEDChannels[j1][1] = (fromgreen * (32 - i) + togreen * i)/32;
LEDChannels[j1][2] = (fromblue * (32 - i) + toblue * i)/32;
}

current LEDChannels[j1][0] value = rr;
current LEDChannels[j1][1] value = gg;
current LEDChannels[j1][2] value = bb;

WriteLEDArray();
delay(15);

}
}

void loop() {
fadeall(1023,0,0,0,0,0,1023);
fadeall(1023,0,0,1023,0,0,0);

if (snState == HIGH) {
LEDChannels[0][0] = rr;
LEDChannels[0][1] = gg;
LEDChannels[0][2] = bb;}
else {
LEDChannels[0][0] = 0;
LEDChannels[0][1] = 0;
LEDChannels[0][2] = 0;}

}

If I could get this to work, then when the button is pressed it will follow the fades current values, and the be off when no pressed.

But like I said, I cant figure this out.

Thanks again for the help

Your fadeall function steps through all the states that the LEDs should be in, with a small delay between iterations of the loop. Think of each iteration of the loop as a state that the LED should be in. Currently, the for loop steps through each state, before the function ends.

Instead, each time the function is called, it could check to see if it was time to change to the next state. If you, change the state, set the LEDs, record the time, and return. If it is not time to change states, just return.

Thanks Paul, I am having trouble figuring out what you are saying but I'm sure I will get it eventually