Last active
December 4, 2019 17:53
-
-
Save brysonian/7b75b52922b4958015d84a446014ed59 to your computer and use it in GitHub Desktop.
Example of sequencing 3 LEDs without nested array
This file contains 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 | |
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