Apparently I2C is easy to use! Well unfortunately it's not for me!
I have a NANO as a slave, which has 4 variables in it (Hrs, Min, etc gained by reading a GPS unit). That all works OK.
I have a UNO as the master which would like to be able to read those 4 variables (all under 255) and then do something with them. Preferably by receiving one variable at a time as and when required, but receiving all 4 variables together might be OK.
I can send a Request from master to slave and the slave will reply instantly with which ever variable is in the Write command. However this obviously only returns one variable, not the four that the slave holds.
I believe a way to do this might be to get the master to send a value and then the slave will return a different variable depending on the value received from the master. If this is the way to go then I think I need to use Wire.onReceive and that's when the problems begin! As soon as I put Wire.onReceive in the 'setup' the program refuses to compile and says "'receiveEvent' was not declared in this scope", I have no idea what this means.
Below is the sketch for the slave which works fine (for one variable). The bits that are commented out are the bits I think I need to add, but can't.
Any help will be massively appreciated.
int Hrs =23; // The value (from GPS) that will be sent to master (UNO)
int Mins =59; // The value (from GPS) that will be sent to master (UNO)
int infofromUNO = 0; // The info I'm trying to get from the master - but can't.
// Wire.onReceive(receiveEvent); //receive data from master
Wire.onRequest(requestEvent); //master requests data from slave
// if (Wire.available())
// infofromUNO = Wire.read();
Wire.write(Mins); //data sent to master when requested.