Skip to content

Instantly share code, notes, and snippets.

@JeffersGlass
Created May 17, 2020 22:53
Show Gist options
  • Save JeffersGlass/8773bf13e2f15eb18747b7e3a2eb8da8 to your computer and use it in GitHub Desktop.
Save JeffersGlass/8773bf13e2f15eb18747b7e3a2eb8da8 to your computer and use it in GitHub Desktop.
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