#include # define I2C_SLAVE_ADDRESS 11 // 12 pour l'esclave 2 et ainsi de suite #define PAYLOAD_SIZE 2 #define LED 4 int n = 1; void setup() { pinMode(LED, OUTPUT); Wire.begin(I2C_SLAVE_ADDRESS); Serial.begin(9600); Serial.println("-------------------------------------I am Slave1"); delay(1000); Wire.onRequest(requestEvents); Wire.onReceive(receiveEvents); digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level) delay(500); // wait for a second digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW } void loop(){ digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level) delay(200*n); // wait for a second digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW delay(200*n); } void requestEvents() { Serial.println(F("---> recieved request")); Serial.print(F("sending value : ")); Serial.println(n); Wire.write(n); } void receiveEvents(int numBytes) { Serial.println(F("---> recieved events")); n = Wire.read(); Serial.print(numBytes); Serial.println(F("bytes recieved")); Serial.print(F("recieved value : ")); Serial.println(n); } //#include // //# define I2C_SLAVE_ADDRESS 11 // 12 pour l'esclave 2 et ainsi de suite // //#define PAYLOAD_SIZE 2 //#define LED 4 //void setup() //{ // pinMode(LED, OUTPUT); // Wire.begin(I2C_SLAVE_ADDRESS); // delay(1000); // Wire.onRequest(requestEvents); // Wire.onReceive(receiveEvents); // digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level) // delay(500); // wait for a second // digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW // delay(500); //} // //void loop(){} // //int n = 0; // //void requestEvents() //{ // Wire.write(n); // digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level) // delay(500); // wait for a second // digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW // delay(500); // digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level) // delay(200); // wait for a second // digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW // delay(200); //} //void receiveEvents(int numBytes) //{ // int n = 0; // n = Wire.read(); // for(int i = 0; i <= 3; i++ ){ // digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level) // delay(1000); // wait for a second // digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW // delay(1000); // } // digitalWrite(LED, LOW); // } // //