#include <Wire.h>

#define SLAVE_ADDRESS 0x12
int dataReceived = 0;

void setup() {
    Serial.begin(9600);
    Wire.begin(SLAVE_ADDRESS);
    Wire.onReceive(receiveData);
    Wire.onRequest(sendData);
    pinMode(13, OUTPUT);
    digitalWrite(13, LOW);
}

void loop() {
    delay(100);
}

void receiveData(int byteCount) {
    while(Wire.available()) {
        dataReceived = Wire.read();
        Serial.print("Donnee recue : ");
        Serial.println(dataReceived);
    }
}

void sendData() {
    if (dataReceived == 1) {
      Serial.println("HIGH");
      digitalWrite(13, HIGH);
    } else {
      Serial.println("LOW");
      digitalWrite(13, LOW); 
    }
    //int envoi = dataReceived + 1;
    //Wire.write(envoi);
    Wire.write(0);
}
