//code for master #include #define SDA_PIN 5 #define SCL_PIN 6 #define SLAVE_ADDR 0x08 void setup() { Serial.begin(115200); Wire.begin(SDA_PIN, SCL_PIN); Serial.println("ESP32 Master Ready"); } void loop() { Serial.println("Sending command: 1"); Wire.beginTransmission(SLAVE_ADDR); Wire.write(1); byte error = Wire.endTransmission(); if (error == 0) { Serial.println("Success"); } else { Serial.print("Error: "); Serial.println(error); } delay(2000); } // code for SLAVE #include #define LED_PIN PIN_PA7 // PA5 pin where LED is connected #define I2C_ADDR 0x08 // I2C address for this device volatile uint8_t command = 0; // Stores received command (volatile → used in interrupt) // ── I2C Receive Callback ─────────────────── void receiveEvent(int howMany) { if (Wire.available()) { command = Wire.read(); // Read incoming command byte } } void setup() { pinMode(LED_PIN, OUTPUT); // Set LED pin as output Wire.begin(I2C_ADDR); // Initialize as I2C Subordinate Wire.onReceive(receiveEvent); // Register callback when data is received } void loop() { if (command == 1) { // If command is 1 → blink LED blinkTwice(); // Call blink function command = 0; // Reset command after execution } } // ── Blink LED twice ──────────────────────── void blinkTwice() { for (int i = 0; i < 2; i++) { digitalWrite(LED_PIN, HIGH); // Turn LED ON delay(200); // Keep it ON for 200ms digitalWrite(LED_PIN, LOW); // Turn LED OFF delay(200); // Keep it OFF for 200ms } }