#define led1 23
int led_b[] = {2, 4, 16, 17, 5, 18, 19, 21};
#define s1 34
#define s2 35
int numLEDs = 8;  
int speed = 300;  
bool s1Pressed = false; 
bool s2Pressed = false; 
void setup() {
  Serial.begin(115200);
  Serial.println("Hello, ESP32!");

  for (int i = 0; i < numLEDs; i++) {
    pinMode(led_b[i], OUTPUT);
    digitalWrite(led_b[i], LOW); 
  }

  pinMode(s1, INPUT_PULLUP);
  pinMode(s2, INPUT_PULLUP);
}

void loop() {
  if (digitalRead(s1) == LOW && !s1Pressed) {
    Serial.println("Button s1 pressed. LEDs rotating up 1 round.");
    for (int round = 0; round < 1; round++) { 
      for (int i = 0; i < numLEDs; i++) {
        digitalWrite(led_b[i], HIGH);
        delay(speed);
        digitalWrite(led_b[i], LOW);
        delay(speed);
      }
    }
    s1Pressed = true;
  }
  if (digitalRead(s1) == HIGH) {
    s1Pressed = false;
  }


  if (digitalRead(s2) == LOW && !s2Pressed) {
    Serial.println("Button s2 pressed. LEDs rotating down 2 rounds.");
    for (int round = 0; round < 2; round++) { // วน 2 รอบ
      for (int i = numLEDs - 1; i >= 0; i--) {
        digitalWrite(led_b[i], HIGH);
        delay(speed);
        digitalWrite(led_b[i], LOW);
        delay(speed);
      }
    }
    s2Pressed = true; 
  }
  if (digitalRead(s2) == HIGH) {
    s2Pressed = false; 
  }

  delay(50);
}