and the link to the group assignment is: FabLabCDMX.
Coding SLAVE———
#include <Wire.h> //library for I2C
byte own_address = 1; //set own adress, changed to 2 in another board.
void setup() {
Wire.begin(own_address); //enter the bus on specified address
Wire.onReceive(receiveEvent);
pinMode(2, OUTPUT); //the pin where your led is connected
digitalWrite(2, HIGH);
}
void loop() {
}
void receiveEvent(int howMany) {
while (Wire.available()) {
char c = Wire.read();
if(c=='H'){
digitalWrite(2,HIGH);//turn LED on
}
else if(c=='L'){
digitalWrite(2,LOW);//turn LED off
}
}
}
Coding MASTER—————
#include <Wire.h>
void setup() {
Serial.begin(115200);
Wire.begin(); // join i2c bus (address optional for master)
pinMode(13,OUTPUT);
}
void loop() {
while (Serial.available()) {
char c = Serial.read();
if(c=='A'){
Wire.beginTransmission(4); //number of the "slave" board
Wire.write('A');
Wire.endTransmission();
Serial.println("writing to address 4!");
}
else if(c=='B'){
Wire.beginTransmission(4);
Wire.write('B');
Wire.endTransmission();
Serial.println("writing to address 4!");
}
else if(c=='H'){
Wire.beginTransmission(2); //number of the "slave" board
Wire.beginTransmission(1);
Wire.write('H');
Wire.endTransmission();
Serial.println("writing to address 2!");
}
else if(c=='L'){
Wire.beginTransmission(2);
Wire.beginTransmission(1);
Wire.write('L');
Wire.endTransmission();
Serial.println("writing to address 2!");
}
}
}
a placeto re-connect