// This example lights up 8 leds in sequence. // The sequence direction is determined by a switch. int p = 0; // holds which led is on int s = 8; // digital i/o pin with switch 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 as 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(200); // wait 200 millisecs }