// Taille maximale pour le tableau des broches (modifiable selon vos besoins)
#define MAX_PINS 40

// Tableau pour stocker l'état précédent de chaque broche
int prevPinState[MAX_PINS];

// Initialisation des valeurs par défaut
void initializePinStates() {
    for (int i = 0; i < MAX_PINS; i++) {
        prevPinState[i] = -1; // -1 pour indiquer un état non initialisé
    }
}

// Macro pour écrire uniquement si l'état change
#define DIGITAL_WRITE(pin, state)                    \
    {                                                \
        if (pin < MAX_PINS) {                        \
            if (state != prevPinState[pin]) {        \
                prevPinState[pin] = state;           \
                Serial.print(state);                 \
                Serial.print(" ");                   \
                Serial.print(pin);                   \
                Serial.println(" changement etat");  \
                digitalWrite(pin, state);            \
            } else {                                 \
                Serial.print(prevPinState[pin]);                 \
                Serial.print(" ");                   \
                Serial.print(pin);                    \
                Serial.println(" meme etat");         \
            }                                        \
        } else {                                     \
            Serial.println("Erreur : broche hors limite"); \
        }                                            \
    }
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("Hello, ESP32!");
  initializePinStates();
}

void loop() {
  DIGITAL_WRITE(13,0);
  DIGITAL_WRITE(12,0);
  DIGITAL_WRITE(13,0);
  DIGITAL_WRITE(12,1);
  DIGITAL_WRITE(13,1);
   Serial.println("*******************");
   delay(5000);
  // put your main code here, to run repeatedly:
  delay(10); // this speeds up the simulation
}
esp:0
esp:2
esp:4
esp:5
esp:12
esp:13
esp:14
esp:15
esp:16
esp:17
esp:18
esp:19
esp:21
esp:22
esp:23
esp:25
esp:26
esp:27
esp:32
esp:33
esp:34
esp:35
esp:3V3
esp:EN
esp:VP
esp:VN
esp:GND.1
esp:D2
esp:D3
esp:CMD
esp:5V
esp:GND.2
esp:TX
esp:RX
esp:GND.3
esp:D1
esp:D0
esp:CLK