I have a sequence to code of around 100 LEDs, I am using the dmx512 protocol to do it, i will be needing to program sequences that snap high or low and fade high and low, I can do all of this ATM by writing each channel of dmx. However is there a better way of doing this? Perhaps using arrays? Is there a way of doing it without writing a value of each led in each step?
Thanks
What is ATM
Post your code
rogerClark:
What is ATMPost your code
Probably ATM = At The Moment.
For fading you can use a for loop to get the transitions, but for the rest of the sequence, that really depends on the sequence itself.
If it is something regular and repetitive, then simple blink without delay approach for each LED will do just fine.
If it is something irregular, you'll need to tell the code what this irregularity looks like, so yes, each step for LED has to be defined.
This is the code I use to drive shift registers with some LEDs. The idea is to simulate turn signals on three cars. I didn't want the blinking to be synced so I introduced a slightly different periods for them to turn on and off. Those values are in an array. Addresses of shift register outputs are in another array. The for loop quickly goes through setting these three outputs to whatever they need to be and moves on to other parts of the code where it sets different pins according to some other logic.
#define numberOfBlinkers 3
int blinkers [] = {
14, 16, 77};
int blinkersTime [] = {
500, 523, 549};
void setBlinkers(){
if (running == true)
{
for (int i = 0; i < numberOfBlinkers; i++)
{
if (blinkersMillis[i] + blinkersTime[i] < millis() )
{
blinkersMillis[i] = millis();
if (blinkersState [i] == LOW)
{
shifter.setPin (blinkers [i], HIGH);
}
else if (blinkersState [i] == HIGH)
{
shifter.setPin (blinkers [i], LOW);
}
}
}
}
Thanks, a quick question
If I defined a function that contained delay() and called it only when a button was pressed would the delay affect the rest of the code running in loop () or would it only apply the delat to the function?
I understand I can use the millis way like you have or use a sine wave but obviously delay() is a lot quicker to code
Thanks
Functions run one at a time so any delay affects that function and also delays the time the next function will run.
This is a single threaded machine.
If you do want to store a predefined flash pattern in an array, you'll want to use PROGMEM to do it. It's a little more complicated than a simple array, but with 100 LEDs, you're going to run out of RAM fast unless you use PROGMEM.