Skip to content

Instantly share code, notes, and snippets.

@acspike
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acspike/7cdb82c73f09a911d1f1 to your computer and use it in GitHub Desktop.
Save acspike/7cdb82c73f09a911d1f1 to your computer and use it in GitHub Desktop.
Using conditionals to light LEDs
int button = 2;
int led = 13;
int leds[] = {5,6,9,10,11};
int leds_count = 5;
int cursor = 0;
int direction = 1;
void setup() {
pinMode(led, OUTPUT);
for (int i=0; i< leds_count; i++) {
pinMode(leds[i], OUTPUT);
}
pinMode(button, INPUT_PULLUP);
}
void loop() {
int pos = analogRead(5);
cursor = floor(pos / 204.8);
for(int i=0; i<leds_count; i++){
if(i==cursor) {
digitalWrite(leds[i], HIGH);
}else{
digitalWrite(leds[i], LOW);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment