// This example lights up 8 leds in sequence. // The sequence direction is determined by a switch on pin 8. #define pinSwitch 8 // digital i/o pin with switch int p = 0; // holds number of LED pin that is "on" void setup() { for (p=0; p<8; p++) { // set digital pins 0-7 as outputs pinMode(p, OUTPUT); digitalWrite(p, LOW); // and set them "off" } pinMode(pinSwitch, INPUT); // set digital pin 8 as input } void loop() { digitalWrite(p, LOW); // set pin p "off" if (digitalRead(pinSwitch) == HIGH) { // if status of the switch is pressed p--; // advance p to previous pin } else { p++; // advance p to next pin } p = (p+8) % 8; // loop p over values 0-7 digitalWrite(p, HIGH); // set pin p "on" delay(200); // wait 200 millisecs }