// DIO sequencer version 4 - using PROGMEM
// - char arrays are flat (one long string, no comma separators)
// - edit array elements using (star) "*" for "ON" and (dot) "." for "OFF"
// - each row in an array must be the same length
// https://forum.arduino.cc/t/uno-nano-dio-sequencer/1364441
#include <avr/pgmspace.h> // for PROGMEM to offload arrays from RAM
byte ledPin[] = {4, 5, 6, 7, 8, 9}; // DIO pins for LEDs. ** Leave pin 2 and 3 for hardware interrupts
int ledCount = sizeof(ledPin) / sizeof(ledPin[0]); // number of LEDs
int columnSpacing = 90; // milliseconds per column - speed control
const char sequence[] PROGMEM = { // note: PROGMEM in use
//12345....1.........2.........3.........4.........5.........6.........7.........8.........9.........1 // columns or elements
"***********................................................................***********.....................................*....********............."
".......*.***..**.*****........................**.***..........*........**.*........*..*...............................*.*...*....*.*................."
".......*.***..**.*****........................**.***..........*........**.*........*..*...............................*.*...*....*.*................."
"***********................................................................***********.....................................*....********............."
".......*.***..**.*****........................**.***..........*........**.*........*..*...............................*.*...*....*.*................."
".......*.***..**.*****........................**.***..........*........**.*........*..*...............................*.*...*....*.*................."
};
const char pause[] PROGMEM = { // (colSpace) * (columns) = loop ms
//12345....1.........2.........3....5 // columns
"...................................."
"...................................."
"...................................."
"...................................."
"...................................."
"...................................."
};
void setup() {
Serial.begin(115200); // start serial communications
for (int i = 0; i < ledCount; i++) // count through LED pins
pinMode(ledPin[i], OUTPUT); // configure pins for OUTPUT
}
void loop() {
sequencer(sequence, sizeof(sequence) / ledCount);
sequencer(pause, sizeof(pause) / ledCount);
}
void sequencer(char list[], int length) {
for (int col = 0; col < length; col++) { // count through row length
for (int row = 0; row < ledCount; row++) { // count through number of LEDs
switch (pgm_read_byte(&list[row * length + col])) { // locate element row and column location
case '*': digitalWrite(ledPin[row], HIGH); break; // LED ON
case '.': digitalWrite(ledPin[row], LOW); break; // LED OFF
default: break;
}
}
delay(columnSpacing); // regulate sequence speed
}
}