/* Example: Create Running LED Patterns (Version A) */
const byte LED_PINS [8] = { 5,6,7,8,9,10,11,12 };
const byte PATTERNS [8] = {B00000001,
B00000010,
B00000100,
B00001000,
B00010000,
B00100000,
B01000000,
B10000000};
byte index = 0; // used as a counter between 0 to 7.
void setup() {
for (int i=1; i < 8; i++) //กำหนดหลอดที่อยากให้แสดง (< 8; i++)
pinMode( LED_PINS[i], OUTPUT ); // use this LED Pin as output
pinMode(2, INPUT);
pinMode(3, INPUT_PULLUP);
if (digitalRead(2) == HIGH) {
// Set index to start from LED 1
index = 0; } // Adjust the starting LED index as needed
}
void loop() {
byte t = PATTERNS[index]; // get byte value from array at current index
for (int i=0; i < 8; i++) { //กำหนดหลอดที่อยากให้แสดง (< 8; i++) เปลี่ยนเลข8เป็นจำนวนที่อยากให้แสดง
digitalWrite( LED_PINS[i], t & 1 ); // write current bit to LED output
t >>= 1; // shift?bit to left by 1
}
if (digitalRead(2)==HIGH){
index = (index+1) % 8; // increment index by 1
}
if (digitalRead(3)==HIGH){
index = (index-1) % 8; // increment index by 1
}
if(index > 7)
{
index = 8;
}
delay(500); // delay for 50 msec
}