#define LEDPIN 1 // where the controller should send the message to this device -- can be anywhere from 8 - 127 #define I2CADDRESS 25 // what's funnier than 24? #include // tells us if this 412 received an 'h' or an 'f' from the controller via I2C bool hReceived = false; bool fReceived = false; void setup() { pinMode(LEDPIN, OUTPUT); Wire.begin(I2CADDRESS); // enable as peripheral at I2CADDRESS -- 0x25 Wire.onReceive(readMessage); // function called when a message over I2C is received digitalWrite(LEDPIN,LOW); // ensure LED is off at start } // read the message, and decode whether or not an 'f' or 'h' is received void readMessage(int bytes){ if(Wire.available()) { // go through each character in the message -- for this test case there should only be 1 char char c = Wire.read(); // read received byte if(c=='h') hReceived = true; // received 'h' if(c=='f') fReceived = true; // received 'f' } } // main loop void loop() { // 'h' is received from controller if(hReceived){ // blink LED once digitalWrite(LEDPIN, HIGH); delay(100); digitalWrite(LEDPIN, LOW); hReceived = false; } // 'f' is received from controller if(fReceived){ // blink LED twice digitalWrite(LEDPIN, HIGH); delay(100); digitalWrite(LEDPIN, LOW); delay(100); digitalWrite(LEDPIN, HIGH); delay(100); digitalWrite(LEDPIN, LOW); fReceived = false; } delay(100); digitalWrite(LEDPIN, LOW); // make sure the LED is off when a message is not received }