/* Example: Create Running LED Patterns (Version A) */
const byte LED_PINS [8] = { 5,6,7,8,9,10,11,12 };
const byte PATTERNS [10] = {B00000001,
B00000010,
B00000100,
B00001000,
B00010000,
B00100000,
B01000000,
B10000000,
};
byte index = 4; // used as a counter between 0 to 7.
void setup() {
pinMode(2, INPUT);
for (int i=0; i < 8; i++) // for each LED pin do
pinMode( LED_PINS[i], OUTPUT ); // use this LED Pin as output
}
void loop() {
byte t = PATTERNS[index]; // get byte value from array at current index
for (int i=0; i < 10; i++) { // for each bit in byte value do ..
digitalWrite( LED_PINS[i], t & 1 ); // write current bit to LED output
t >>= 1; // shift?bit to left by 1
}
if(digitalRead(2) == LOW)
index = (index +1);
delay(100); // delay for 50 msec
}