My master code:
#include <Wire.h>
const byte SLAVE_ADD1 = 1;
const byte SLAVE_ADD2 = 2;
const byte SLAVE_ADD3 = 3;
const byte SLAVE_ADD4 = 4;
const byte MY_ADD = 10;
int Address ;
void setup() {
Wire.begin(MY_ADD);
}
void loop() {
for (byte x = 2; x <= 7; x++)
{
if (Address == 1 )
{
Wire.beginTransmission (SLAVE_ADD1);
Wire.write (x);
Wire.endTransmission();
}
else if (Address == 2)
{
Wire.beginTransmission (SLAVE_ADD2);
Wire.write (x);
Wire.endTransmission();
}
else if (Address == 3)
{
Wire.beginTransmission (SLAVE_ADD3);
Wire.write (x);
Wire.endTransmission();
}
else if (Address == 4)
{
Wire.beginTransmission (SLAVE_ADD4);
Wire.write (x);
Wire.endTransmission();
}
else
{
Serial.println("ERROR");
}
delay (2000);
return 0 ;
} // end of for loop
} // end of loop
And my slave code:
#include <grbl.h>
#include <Wire.h>
const byte MY_ADD = 1;
const byte OTHER_ADD = 10;
void setup()
{
Wire.begin (MY_ADD);
for (byte i = 2; i <= 7; i++)
{
Wire.onReceive (receiveEvent);
} // end of setup
}
void loop()
{
}
void receiveEvent (int howMany)
{
for (int i = 0; i < howMany; i++)
{
byte c = Wire.read ();
} // end of receiveEvent
}
Please check this out and help me to finish my University project because my teachers
are pressing me.If something is wrong i'll be happy with any corrections. Best regard