#include <Wire.h> // required library
int LED = 13; //initialize pin 13 (led)
int x = 0; //initialize variable x
void setup() {
pinMode (LED, OUTPUT); // Define pin13 as Output
Wire.begin(9); // Start the I2C Bus as Slave on address 9
Wire.onReceive(receiveEvent); // Attach a function to trigger when something is received.
}
void receiveEvent(int bytes) {
x = Wire.read(); // read one character from the I2C
}
void loop() {
//If value received is 0 blink LED for 200 ms
if (x == 0) {
digitalWrite(LED, HIGH);
delay(200);
digitalWrite(LED, LOW);
delay(200);
}
//If value received is 3 blink LED for 400 ms
if (x == 3) {
digitalWrite(LED, HIGH);
delay(400);
digitalWrite(LED, LOW);
delay(400);
}
}