Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const int leds[] = {9, 10, 11, 12, 13};
const int NUMLEDS = 5;
const int knobPin = A5;
const int button1 = 7;
const int button2 = 8;
int loopStep = 1;
int i = 0;
void setup() {
// put your setup code here, to run once:
for (int i = 0; i < NUMLEDS; i++){
pinMode(leds[i], OUTPUT);
digitalWrite(leds[i], LOW);
}
pinMode(knobPin, INPUT);
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(leds[i], HIGH);
delay(analogRead(knobPin));
digitalWrite(leds[i], LOW);
i = (i + loopStep) % NUMLEDS;
if (i < 0) i = NUMLEDS-1;
if (digitalRead(button1) == LOW) loopStep = -1;
if (digitalRead(button2) == LOW) loopStep = 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment