// Minimal I2C slave that ACKs writes at address 0x12
// Reads and discards incoming bytes so the master write is acknowledged
#include <Wire.h>
const uint8_t SLAVE_ADDR = 0x12; // 18 decimal
void setup() {
Wire.begin(SLAVE_ADDR); // start as slave at 0x12
Wire.onReceive(onReceive); // handle master write transfers
// LED gives a short visual indication of activity
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
}
void loop() {
// No active work required in loop for this simple slave
delay(200);
}
// Called when the master writes to this slave
void onReceive(int bytes) {
// Read and discard all incoming bytes so the master sees ACKs
while (Wire.available()) {
(void)Wire.read();
}
// Short LED flash to indicate a received transfer
digitalWrite(LED_BUILTIN, HIGH);
delay(40);
digitalWrite(LED_BUILTIN, LOW);
}