#include #define SLAVE_ADDR 8 // 从机地址 void setup() { Wire.begin(); // 初始化 I2C 主机 Serial.begin(9600); // 串口监控 Serial.println("Master ready. Press 'A' to turn ON LED, 'B' to turn OFF LED on slave."); } void loop() { if (Serial.available() > 0) { char c = Serial.read(); if (c == 'A' || c == 'B') { Wire.beginTransmission(SLAVE_ADDR); Wire.write(c); // 发送字符 Wire.endTransmission(); Serial.print("Sent: "); Serial.println(c); } } }