Skip to content

Instantly share code, notes, and snippets.

@brysonian
Last active December 4, 2019 17:53
Show Gist options
  • Save brysonian/7b75b52922b4958015d84a446014ed59 to your computer and use it in GitHub Desktop.
Save brysonian/7b75b52922b4958015d84a446014ed59 to your computer and use it in GitHub Desktop.
Example of sequencing 3 LEDs without nested array
int tempo = 250; // just the delay in milliseconds at the end of loop
const int LED_PIN_1 = 12;
const int LED_PIN_2 = 11;
const int LED_PIN_3 = 10;
unsigned long counter = 0;
int measure = 4;
int sequence1[] = {
1, 0, 1, 0
};
int sequence2[] = {
1, 0, 0, 0
};
int sequence3[] = {
1, 1, 1, 1
};
void setup() {
pinMode(LED_PIN_1, OUTPUT);
pinMode(LED_PIN_2, OUTPUT);
pinMode(LED_PIN_3, OUTPUT);
}
void loop() {
int beat = counter % measure;
if (sequence1[beat]) {
hit(LED_PIN_1);
}
if (sequence2[beat]) {
hit(LED_PIN_2);
}
if (sequence3[beat]) {
hit(LED_PIN_3);
}
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