Skip to content

Instantly share code, notes, and snippets.

@brysonian
Last active December 4, 2019 17:52
Show Gist options
  • Save brysonian/a1867f1c73f537a6544391b9df3b609e to your computer and use it in GitHub Desktop.
Save brysonian/a1867f1c73f537a6544391b9df3b609e to your computer and use it in GitHub Desktop.
Example of Sequencing 3 LEDs with nested arrays
int tempo = 250; // just the delay in milliseconds at the end of loop
int tracks = 3;
int trackPins[] = {
12, 11, 10
};
int measure = 4;
int sequences[][4] = {
{ 1, 0, 1, 0 },
{ 1, 0, 0, 0 },
{ 1, 1, 1, 1 }
};
unsigned long counter = 0;
void setup() {
for (int i = 0; i < tracks; i++) {
pinMode(trackPins[i], OUTPUT);
}
}
void loop() {
int beat = counter % measure;
for (int i = 0; i < tracks; i++) {
if (sequences[i][beat]) {
hit(trackPins[i]);
}
}
counter++;
delay(tempo);
}
void hit(int pin) {
digitalWrite(pin, HIGH);
delay(20);
digitalWrite(pin, LOW);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment