Skip to content

Instantly share code, notes, and snippets.

@futureshocked
Created October 26, 2019 04:45
Show Gist options
  • Save futureshocked/a8fb3124ddf95f8143ca9895999715e8 to your computer and use it in GitHub Desktop.
Save futureshocked/a8fb3124ddf95f8143ca9895999715e8 to your computer and use it in GitHub Desktop.
Control an LED using an array.
/*
* Control an LED using an array.
*
* Create a pattern with LED on and off information in one array,
* and on/off durations in a second array.
*
*
*/
const int ledPin = 7;
const int totalStates = 9;
int ledState[totalStates] = {1, 0, 1, 0, 1, 0, 0, 1, 0};
int ledDuration[totalStates] = {200,400,500,100,200,50, 50, 500, 500 };
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
for (int i = 0; i < totalStates; i++)
{
digitalWrite(ledPin,ledState[i]);
delay(ledDuration[i]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment