Last active
August 29, 2015 14:01
-
-
Save acspike/7cdb82c73f09a911d1f1 to your computer and use it in GitHub Desktop.
Using conditionals to light LEDs
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 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