/*
  author: liangjingheng
  date: 2025-10-14
  company: waveshare
*/
#define NUM_LEFT 11  // Number of left GPIO pins
#define NUM_RIGHT 9 // Number of right GPIO pins

// Left GPIO pins 
const int left_gpios[NUM_LEFT] = {0, 1, 2, 3, 6, 7, 8, 9, 10, 25, 26};
// Right GPIO pins 
const int right_gpios[NUM_RIGHT] = {24, 23, 15, 27, 5, 4, 28, 14, 13};

void setup() {
  Serial.begin(115200); // Initialize serial port (for printing information)
  
  // Initialize left GPIOs: output mode, default low level
  for (int i = 0; i < NUM_LEFT; i++) {
    pinMode(left_gpios[i], OUTPUT);
    digitalWrite(left_gpios[i], LOW);
    Serial.printf("Left GPIO %d initialized to LOW.\n", left_gpios[i]);
  }

  // Initialize right GPIOs: output mode, default high level
  for (int i = 0; i < NUM_RIGHT; i++) {
    pinMode(right_gpios[i], OUTPUT);
    digitalWrite(right_gpios[i], HIGH);
    Serial.printf("Right GPIO %d initialized to HIGH.\n", right_gpios[i]);
  }
}

void loop() {
  // Left GPIOs: HIGH → LOW (execute one by one)
  for (int i = 0; i < NUM_LEFT; i++) {
    digitalWrite(left_gpios[i], HIGH);
    Serial.printf("Left GPIO %d set to HIGH.\n", left_gpios[i]);
    delay(300); // Delay for 300ms to ensure visibility of the effect
    
    digitalWrite(left_gpios[i], LOW);
    Serial.printf("Left GPIO %d set to LOW.\n", left_gpios[i]);
    delay(300);
  }

  // Right GPIOs: LOW → HIGH (execute one by one)
  for (int i = 0; i < NUM_RIGHT; i++) {
    digitalWrite(right_gpios[i], LOW);
    Serial.printf("Right GPIO %d set to LOW.\n", right_gpios[i]);
    delay(300);
    
    digitalWrite(right_gpios[i], HIGH);
    Serial.printf("Right GPIO %d set to HIGH.\n", right_gpios[i]);
    delay(300);
  }
}