void Request1()
{
Wire.requestFrom(address, 3); //An error here
byte index=0;
while(Wire.available() > 0 && index < 3)
{
S1IN[index] = Wire.read();
index++;
}
}
void Request2()
{
Wire.requestFrom(address2, 2); //Also an error here
byte index=0;
while(Wire.available() > 0 && index < 2)
{
S2IN[index] = Wire.read();
index++;
}
}
When i try to compile it gives the error stated above, I tried declaring "byte index" before the setup with the rest of the arrays. What i get least of all however is, that in a different code i used to test the Wire.h library, i used the same "request" function with no problems.....
This is the master code for the robot I am building with my Engineering class, the arrays exist of the OUTgoing bits of information, and the INcomming bits, directed at 2 slaves. Then there is the choice diagram of if statements, and then the functions to send and receive the information over I2C
I would like to, but as far as i can see it's the best solution for this problem, the idea is: the master compares the ready bit if 1 or 0, if 0: write bit "x" 1 and continue with the rest of the comparisons. If 1 continue straight away.
if(S1IN[0] == 1) //so are we ready?
{
US:
if(Usensing()==1) //yes we are, lets see if we can see something
{
S2OUT[1]=1;
if(S1IN[1] == 1)
{
S2OUT[0]=0; //remmen =0
S2OUT[1]=0; //rijden =0
}
}
else
{
S2OUT[1]=1; //remmen =1
}
}
else //It appears we are not quite ready
{
S1OUT[0]=1; //so ready up
goto US; //and check your sensors
}
but as far as i can see it's the best solution for this problem
"goto" is rarely the best solution to anything, except getting yourself out of a mess.
The way you have it, it looks like you're getting yourself into a mess.
It isn't clear to me what the logic is, but a "so..while" or a "while" loop may be a better choice.