So I am tinkering with some existing code that I might be able to adapt to my needs... this code was written by Chagrin back in 2012 and it allows dimming of the LEDs and acceleration of the rate of change between outputs, so in theory the lights can be made to speed up, slow down, and dim up and down - whatever. Which would make for a pretty cool reel spin simulation. I have set up an initial small sequence of symbol commands, each flashing at full brightness at 100 millisecond intervals. As it is the sequence will only run once. I need to loop this sequence and make it stop mid stream on a ground lift/switch/timer... Given my tiny programming skill set this seemed like a way forward, but I do see that it is not what you are suggesting Mike, and I apologise in advance.
/*
Fade up and down on multiple pins
Code adopted from Chagrin August 2012
*/
#define LED1 2 // Cherries
#define LED2 3 // Orange
#define LED3 4 // Lemon
#define LED4 5 // Plums
#define LED5 6 // Bell
#define LED6 7 // Bar
#define MAXPINNUMBER 7 // LED6 is the highest pin number -- number 7
#define MILLISPERDIMSTEP 100 // LED dimming is recalculated every X millis
// Group LED commands into a structure (struct)
struct command {
byte pin; // 0 to 255
unsigned int time; // 0 to 65535
byte brightness; // 0 to 255
char dimrate; // -127 to 128
};
// The stored state of each LED; holds state of dimming.
struct state {
unsigned int time;
byte brightness;
byte dimrate;
};
// Create the reel spin which is an array of "command" structs
struct command scene[] = {
{LED1,0,255,0},
{LED2,0,0,0},
{LED3,0,0,0},
{LED4,0,0,0},
{LED5,0,0,0},
{LED6,0,0,0},
{LED1,100,0,0},
\{LED1,100,0,0},
{LED2,100,255,0},
{LED2,200,0,0},
{LED3,200,255,0},
{LED3,300,0,0},
{LED4,300,225,0},
{LED4,400,0,0},
{LED5,400,255,0},
{LED5,500,0,0},
{LED6,500,255,0},
{LED6,600,0,0},
};
// Initialize the LED states to off. Note 0 to MAXPINNUMBER is (MAXPINNUMBER + 1) states.
struct state ledState[MAXPINNUMBER + 1] = {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},};
void setup(){
}
void loop(){
static unsigned long kickoff = 0;
static unsigned int sceneCtr = 0;
byte ledCtr = 0;
// wait for a button press here to kick off the scene if desired
// Check the scene to see if we have a new command
if (sceneCtr < sizeof(scene) / sizeof(command)) {
if (scene[sceneCtr].time <= millis() - kickoff) {
analogWrite(scene[sceneCtr].pin, scene[sceneCtr].brightness);
if (scene[sceneCtr].dimrate != 0) {
// It dims; we have to add this to our ledState array and keep track of it.
ledState[scene[sceneCtr].pin].time = scene[sceneCtr].time + MILLISPERDIMSTEP;
ledState[scene[sceneCtr].pin].brightness = scene[sceneCtr].brightness;
ledState[scene[sceneCtr].pin].dimrate = scene[sceneCtr].dimrate;
}
sceneCtr += 1;
}
}
// Here we process through all the LEDs in a dimming state
for (ledCtr = 0; ledCtr < MAXPINNUMBER + 1; ledCtr++) {
if (ledState[ledCtr].dimrate != 0) { // only LEDs with a dimming are messed with.
if (ledState[ledCtr].time <= millis() - kickoff) {
if (ledState[ledCtr].brightness + (char) ledState[ledCtr].dimrate >= 0 &&
ledState[ledCtr].brightness + (char) ledState[ledCtr].dimrate <= 255) {
ledState[ledCtr].brightness += (char) ledState[ledCtr].dimrate;
ledState[ledCtr].time += MILLISPERDIMSTEP; // mark the time of next LED adjustment
} else if (ledState[ledCtr].brightness + (char) ledState[ledCtr].dimrate < 0) {
// need to stop at zero and not a negative number.
ledState[ledCtr].brightness = 0;
ledState[ledCtr].dimrate = 0; // zero dimrate so we stop dimming it
} else {
// need to stop at 255.
ledState[ledCtr].brightness = 255;
ledState[ledCtr].dimrate = 0; // zero dimrate.
}
analogWrite(ledCtr, ledState[ledCtr].brightness);
}
}
}
// Have 60 seconds elapsed? We need to restart if so.
if (millis() - kickoff > 600000) {
kickoff = millis();
sceneCtr = 0;
}
}