After actually wiring it up, it looks like the PROGMEM keyword is causing problems; I'm not sure why. For now, remove it. Hopefully someone else will chime in as to the issue.
Tom-Kristensen:
Another thing that surprises me is that the entire scene is to be set out in the section of code that defines the constants for the program ie before the void setup. Is this really right?
Yes that's correct. See scope - Arduino Reference for an explanation.
Tom-Kristensen:
Interestingly When I tried to replace the early short scene string with your later longer string the compiler was not happy: attributes are not allowed on a function definition. Hmmm, I guess I better experiment with moving the string around. I see some knots coming up.
I made a mistake and left out the "=" sign. That should be unsigned int scene[] = {LED1...
Reposting the code, and now guaranteeing that it will work ![]()
#define LED1 3 // assign the first LED to pin 3
#define LED2 5 // assign the second LED to pin 5, etc...
#define LED3 6
unsigned int scene[] = {LED1,0,255,LED2,0,255,LED3,0,255,LED1,1000,0,LED2,2000,0,LED3,3000,230,LED3,3100,205,LED3,3200,180,LED3,3300,155,LED3,3400,130,LED3,3500,105,LED3,3600,80,LED3,3700,55,LED3,3800,30,LED3,3900,5,LED3,4000,0};
void setup(){
}
void loop(){
unsigned int ctr = 0;
// wait for a button press here to kick off the scene if desired
unsigned long kickoffTime = millis();
while (ctr < sizeof(scene) / sizeof(unsigned int)) {
if (scene[ctr + 1] <= millis() - kickoffTime) {
analogWrite(scene[ctr], scene[ctr + 2]);
ctr += 3; // each command is 3 unsigned ints; we jump to the next command.
}
}
while (millis() - kickoffTime < 60000) {} // idle loop; wait for 60 seconds to expire if not already.
}
With this scene all of the LEDs should turn on, then two turn off a second later and a second apart, and the third fades out. The entire scene should replay, repeatedly, every 60 seconds.