mahban.irandoust:
I added another function ( colorDisappear ). However I could not manage to change the last LEDs into red and then turn them off. it turns each red and then off.
[void colorDisappear (uint32_t c1,uint8_t wait1, uint32_t c2, uint8_t wait2) {
for (int j=0; j < strip.numPixels(); j++) {
if (j < 28){
strip.setPixelColor(j, c1);
strip.show();
delay(wait1);
}
else {
strip.setPixelColor(j, c2);
strip.show();
delay(wait2);
strip.setPixelColor(j, c1);
strip.show();
delay(wait1);]
What were you trying to do with the above ? Originally you said :
mahban.irandoust:
I need a program to turn on all LEDs (32 LEDs) in white color and afterwards turining them off (one by one). when this (turn-off) reaches to the last 6 LEDs, switch their color into pink and then turn them off.
again, when "turn-off’reaches to the last 2 LEDs, switch thir color into red and then turn them off.
You now say “However I could not manage to change the last LEDs into red and then turn them off. it turns each red and then off.” Huh ? Let me make sure I understand. Now you want some number of the “last” LEDs to all turn red and then, after some time, all turn off. What you’re getting is each of the “last” LEDs turns red and then off and then the next LED does the same, etc, etc. I’d expect this latter behavior given your code above. Look at this part :
else {
strip.setPixelColor(j, c2);
strip.show();
delay(wait2);
strip.setPixelColor(j, c1);
strip.show();
delay(wait1);]
Let j = 28 and what happens ? The code executes the above just as you wrote it. It sets pixel 29 to color c2 (red) then waits “wait2” msecs then sets pixel 29 to color c1 (off) and waits “wait1” msecs before incrementing j and doing it for the next pixel.
I note that 32 pixels (1-32) are controlled by j from 0-31 and j = 28 doesn’t correspond to either the last 6 or the last 2 pixels.
mahban.irandoust:
I also tried this one which doesn’t work. I could not find why!!!
[void colorDisappear (uint32_t c1,uint8_t wait1, uint32_t c2, uint8_t wait2) {
for (int j=0; j < strip.numPixels(); j++) {
if (j < 28){
strip.setPixelColor(j, c1);
strip.show();
delay(wait1);
}
else {
strip.setPixelColor(j, c2);
strip.show();
delay(wait2);
if (j = strip.numPixels()){
for (int k=28; k < strip.numPixels(); k++) {
strip.setPixelColor(k, c1);
strip.show();
delay(wait1);
}
}
}
}
}]
So what did the above do ? Hint : what’s the largest value j can get to and still have the code above execute ?
http://www.arduino.cc/en/Reference/For
mahban.irandoust:
and the void loop is:
[void loop() {
colorAppear (Color(255, 255, 255), 50);
colorDisappear (Color(0, 0, 0),50000, Color(255, 0, 0) , 50);
}]
I really appreciate all your helps.
I would do things differently but there are many ways to do what you want (though I’m not sure exactly what that is now). One thing I will point out, and I think it was wrong in the library code as well, is that the “wait” variable was declared as an unsigned 8 bit value. That can only store a number up to 255. I don’t know what happens when you try to stuff a delay greater than 255 into it.