Version 1 - Passing two-dimension, character array to a single function. (scaling failed - skip to V3)
Text based DIO sequencer for Uno/Nano R3. No millis();
required. Useful for simulated lightning, fireworks, dancing sprinklers, player bells, relay music, et c. Extend sequence lines to limit of memory.
// DIO sequencer
// Edit the sequence elements. "*" and "." only, or edit the switch/case.
const int seqlen = 100; // sequence length MUST BE DEFINED (multiply times "speed" for loop time)
const char sequence[][seqlen] = { // array of sequenced elements
//12345....1.........2.........3.........4.........5.........6.........7.........8.........9.........1 // elements
{"********...........*.......*..........*...*...*.........*.....*......*.....*...*.................*.."}, // LED[0]... sequence[0][0..n]
{"***********.......*.........*.........*...*...*........*......*.........*........*.............*...."}, // LED[1]... sequence[1][0..n]
{"**************...*...........*........*...*...*.......*.......*......*......*......*.........*......"}, // LED[2]... sequence[2][0..n]
{".......................................*.*...........*........*.........*............*.....*........"},
{"...*................................*.....*.........*.........*......*......*..........*.*.........."},
{"......*..........................*.........*.......*..........*.........*..............*.*.........."}, // EXTENSIBLE --->
{".........*....................*.............*.....*...........*......*......*........*.....*........"},
{"............*..............*.................*...*............*.........*..........*.........*......"},
{"...............*........*.....................*.*.............*......*......*....*.............*...."},
{"..................*..*.........................*..............*.........*......*.................*.."}, // LED[9]... sequence[9][0..n]
};
byte ledPin[] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; // LED pins
int arraySize = sizeof(ledPin) / sizeof(ledPin[0]);
int speed = 50; // milliseconds per element - speed control (multiply time "seqlen" for loop time)
void setup() {
Serial.begin(115200);
for (int i = 0; i < arraySize; i++)
pinMode(ledPin[i], OUTPUT); // start on DIO pin 4
loopTime();
}
void loop() {
for (int seq = 0; seq < seqlen; seq++) { // count through the sequence 0..n
for (int arr = 0; arr < arraySize; arr++) { // read "seq" value from each array
switch (sequence[arr][seq]) {
case '*': digitalWrite(ledPin[arr], HIGH); break; // turn LED ON
case '.': digitalWrite(ledPin[arr], LOW); break; // turn LED OFF
default: break;
}
}
delay(speed); // intra-sequence delay
}
}
void loopTime() {
Serial.print("Loop Time (");
Serial.print(speed * seqlen);
Serial.print("ms)");
Serial.print(" = speed (");
Serial.print(speed);
Serial.print("ms) * sequence length (");
Serial.print(seqlen);
Serial.println(" elements)");
}
diagram.json for wokwi.com
{
"version": 1,
"author": "Anonymous maker",
"editor": "wokwi",
"parts": [
{ "type": "wokwi-arduino-nano", "id": "nano", "top": 62.4, "left": 9.1, "attrs": {} },
{
"type": "wokwi-resistor",
"id": "r1",
"top": 32.2,
"left": 37.55,
"rotate": 270,
"attrs": { "value": "333" }
},
{
"type": "wokwi-resistor",
"id": "r2",
"top": 32.2,
"left": 47.15,
"rotate": 270,
"attrs": { "value": "333" }
},
{
"type": "wokwi-resistor",
"id": "r3",
"top": 32.2,
"left": 75.95,
"rotate": 270,
"attrs": { "value": "333" }
},
{
"type": "wokwi-resistor",
"id": "r4",
"top": 32.2,
"left": 56.75,
"rotate": 270,
"attrs": { "value": "333" }
},
{
"type": "wokwi-resistor",
"id": "r5",
"top": 32.2,
"left": 66.35,
"rotate": 270,
"attrs": { "value": "333" }
},
{
"type": "wokwi-resistor",
"id": "r6",
"top": 32.2,
"left": 27.95,
"rotate": 270,
"attrs": { "value": "333" }
},
{
"type": "wokwi-led-bar-graph",
"id": "bargraph1",
"top": -52.6,
"left": 43.4,
"rotate": 270,
"attrs": { "color": "white" }
},
{
"type": "wokwi-resistor",
"id": "r7",
"top": 32.2,
"left": -0.85,
"rotate": 270,
"attrs": { "value": "333" }
},
{
"type": "wokwi-resistor",
"id": "r8",
"top": 32.2,
"left": 8.75,
"rotate": 270,
"attrs": { "value": "333" }
},
{
"type": "wokwi-resistor",
"id": "r9",
"top": 32.2,
"left": 18.35,
"rotate": 270,
"attrs": { "value": "333" }
},
{
"type": "wokwi-resistor",
"id": "r10",
"top": 32.2,
"left": -10.45,
"rotate": 270,
"attrs": { "value": "333" }
}
],
"connections": [
[ "r3:2", "bargraph1:A10", "green", [ "h0" ] ],
[ "r5:2", "bargraph1:A9", "green", [ "h0" ] ],
[ "r4:2", "bargraph1:A8", "green", [ "h0" ] ],
[ "r2:2", "bargraph1:A7", "green", [ "h0" ] ],
[ "r1:2", "bargraph1:A6", "green", [ "h0" ] ],
[ "r6:2", "bargraph1:A5", "green", [ "h0" ] ],
[ "r9:2", "bargraph1:A4", "green", [ "h0" ] ],
[ "r8:2", "bargraph1:A3", "green", [ "h0" ] ],
[ "r7:2", "bargraph1:A2", "green", [ "h0" ] ],
[ "r10:2", "bargraph1:A1", "green", [ "h0" ] ],
[ "bargraph1:C10", "bargraph1:C9", "gray", [ "v0" ] ],
[ "bargraph1:C9", "bargraph1:C8", "gray", [ "v0" ] ],
[ "bargraph1:C8", "bargraph1:C7", "gray", [ "v0" ] ],
[ "bargraph1:C7", "bargraph1:C6", "gray", [ "v0" ] ],
[ "bargraph1:C6", "bargraph1:C5", "gray", [ "v0" ] ],
[ "bargraph1:C5", "bargraph1:C4", "gray", [ "v0" ] ],
[ "bargraph1:C4", "bargraph1:C3", "gray", [ "v0" ] ],
[ "bargraph1:C3", "bargraph1:C2", "gray", [ "v0" ] ],
[ "bargraph1:C2", "bargraph1:C1", "gray", [ "v0" ] ],
[ "nano:13", "r10:1", "white", [ "v-48", "h-9.6" ] ],
[ "r7:1", "nano:12", "white", [ "h0" ] ],
[ "r8:1", "nano:11", "white", [ "h0" ] ],
[ "r9:1", "nano:10", "white", [ "h0" ] ],
[ "r6:1", "nano:9", "white", [ "h0" ] ],
[ "r1:1", "nano:8", "white", [ "h0" ] ],
[ "r2:1", "nano:7", "white", [ "h0" ] ],
[ "r4:1", "nano:6", "white", [ "h0" ] ],
[ "r5:1", "nano:5", "white", [ "h0" ] ],
[ "r3:1", "nano:4", "white", [ "h0" ] ],
[ "nano:GND.2", "bargraph1:C10", "black", [ "v0" ] ]
],
"dependencies": {}
}