Last active
December 4, 2019 17:52
-
-
Save brysonian/a1867f1c73f537a6544391b9df3b609e to your computer and use it in GitHub Desktop.
Example of Sequencing 3 LEDs with nested arrays
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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