Hello. From my knowledge Wire.onRequest() allows you to send send data to Master on request. However what if I want to request 2 different types of data?
For example,
Master will request from slave A an 'OK' on start up. After that
Master will request again from slave A an input data.
void startupTest()
{
Wire.requestFrom(8, 4);
while (Wire.available())
{
char startA = Wire.read(); // receive a byte as character
Serial.print(startA); // print the character
}
}
void requestA()
{
Wire.requestFrom(8, 6);
while(Wire.available())
{
float A = Wire.read();
float displayA = A / 255;
Serial.print(displayA);
}
}
void loop() {
startupTest();
while(1){
requestA();
}
}
Was wondering if the above code would work?
Therefore my question is, how would I let the slave know the difference between the first request and any other request?
No, because it will not compile without code. Please post whole code only! http://snippets-r-us.com
But assuming a setup with a Serial.begin() and a Wire.begin() (and that would also be the place for startupTest() instead of the ugly while(1)), then kind of. But how does the slave know the difference between the first request and any other request?
And a float from a single byte is not going to work A float is 4 bytes
@septillion Yes definitely there is the "Serial.begin() and a Wire.begin()" , that is my bad on that for not posting it.
septillion:
But how does the slave know the difference between the first request and any other request?
And a float from a single byte is not going to work A float is 4 bytes
Now that is a better phrasing of my question, how would I let the slave know the difference between the first request and any other request?
Also what does it mean by "And a float from a single byte is not going to work A float is 4 bytes :)" ?