Light seqence programing

for my next project i am looking at creating a multi light display/show. it will consist of 18 (more later) different light sets that play through different sequences. my problem is i dont know how to write a sketch that will allow me to do this. since i am very new to arduino, i only know how to do the digitalwrite then delay type of thing but that would take forever even on short patterns with 18+ outputs. i would use the mega so would have no issues with the number of outputs avalible. im just looking for a quicker way to create the program that will let me do this. is there any programing shortcuts or ways to have it run through a list of numbers that corispond to the bianary value of the ouput or even better a piece of software that would allow you creat the sequences in a visual way?

oh and one more thing, this is going to need to be a standalone unit, it will need to be able to run it all on its own


One way would be to check the time every second (or whatever) and have the outputs change based on the bits in 4 bytes (32 bits).

Something like this:

for (x = 0; x<100; x=x+4){  // for 25 light sequence
PORTA = array[x];
PORTB = array[x+1];
PORTC = array[x+2];
PORTC = array[x+3};

Some other stuff is needed, like setting the ports to outputs, etc., but nothing too complicated.

i do like the idea of having it check the time on a specific interval and your ways does not sound hard at all. but i basicly dont understand any of that code. (im clueless about most code)

care you explain it for a newb?

PORTA is a whole set of I/O pins.

BTW, all those things can be searched right from the forum. Search box is upper-right.

oh i think i understand the PORTA thing now. its a way to write (or read) a set of 8 outputs with a single binary number right?

i read the page on port registers and it helped alot. now what i don't understand is how to have it check the time at specific times. if you know of a page explaining this it would be greatly appreciated as my searching did not help

I could explain it, but just not starting at 11pm :) Have you done any searching yet?

Basically, I'm thinking something like this could work You set up some variables:

unsigned long current_time = 0;  // 32-bit variable from 0 to 2^31-1
unsigned long elapsed_time = 0;
unsigned long duration = 1000;  // 1 second
unsigned long previous_time = 0;
// declare other variables
int x = 0;
display [100]; // 100 element array, from 0 to 99
display [0,1,2,3] = 0x00112233;  // not sure if that syntax is allowed ...
display [4,5,6,7] = 0x44556677; // but these values would be the 0's (off) and 1's (on) for the LED states
display [96,97,98,99] = 0xCCDDEEFF;
int x = 0;  // start array counter

then in setup you define the ports as outputs

void setup(){
DDRA = 0xFF; // Data Direction Register for Port A, set all bits to outputs (1)
DDRB = 0xFF; 
DDRC = 0xFF; 
DDRD = 0xFF; // ajdsut these for the actual ports you use

then in loop

void loop(){
current_time = millis(); // capture current time
elapsed_time = current_time - previous_time;
if (elapsed_time >=duration) {  // has 1 second passed?
PORTA = display[x]; // element 0
PORTB = display[x+1]; // element 1
PORTC = display[x+2]; // element 2
PORTD = display[x+3}; // element 3
previous_time = current_time; // set up for next time period
x=x+4; // set up for next pass
if (x== 100){ x = 0;}  // reset to go back to top of array

I think this should give you the idea of a simple way to do your sequences. Then you can add reading of some pushbuttons, or serial data, to select between various sequences, change the speed, etc. All kinds of options.

thanks alot for that example code. i now have a mega so that will make it easier to start learning

ive been looking over it and i am confused as to what "display" is?

also if you could clalify how exactly it moves onto the next set of outputs to display that would be awesome.

display [100] is an array holding 100 data elements holding your patterns.

x is the address within the array that will be read.
It increments by 4 every pass thru loop for the next set of data.