// This example lights up 8 leds in sequence. // The sequence direction is determined by a switch. // The sequence speed is set with a potentiometer. int p = 0; // holds which led is on int s = 8; // digital i/o pin with switch int r = 0; // analog input pin with potmeter void setup() { for (int i=0; i<8; i++) { // set digital pins 0-7 as outputs pinMode(i, OUTPUT); } pinMode(s, INPUT); // set digital pin 8 to input } void loop() { if (digitalRead(s) == LOW) { // read status of the switch p++; // advance p to next pin } else { p--; // set p to previous pin } p = (p+8) % 8; // limit p between 0-7 for (int i=0; i<8; i++) { if (i == p) { // set pin p HIGH digitalWrite(i, HIGH); } else { digitalWrite(i, LOW); // and all other pins LOW } } delay(analogRead(r)); // wait 0-1023 millisecs }