Expected primary expression before '=' token, I fail to see the mistake

so I have this bit of code:

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.....

so I have this bit of code

And here is a bit of an answer: Post all your code.

Very well, its not done quite yet, and annotations are partly in Dutch...

//master test 2

#include <Wire.h>

#define address = 1
#define address2 = 2

int Usensor;

byte S1OUT[] = {0,0};  //slave 1 uitgaand, 0 is PREP, 1 is PAKFLES

byte S2OUT[] = {0,0}; //slave 2 uitgaand, 0 is RIJDEN, 1 is REMMEN

byte S1IN[] = {0,0,0};  //slave 1 inkomend, 0 is READY, 1 is IR, 2 is FLES

byte S2IN[] = {0,0};  //slave 2 inkomend, 0 is BEWEGEN, 1 is KRUIS

byte index;

void Send1();
void Send2();
void Request1();
void Request2();

void setup()
{
  Wire.begin();
  Serial.begin(9600);
}

void loop()
{
  Request1;
  delay(10);
  Request2;
  
  if(S2IN[0] == 1)
  {
    if(S1IN[0] == 1)
    {
      US:
      if(Usensing()==1)
      {
        S2OUT[1]=1;
        if(S1IN[1] == 1)
        {
          S2OUT[0]=0; //remmen =0
          S2OUT[1]=0; //rijden =0
        }
     }
      else
      {
        S2OUT[1]=1; //remmen =1
      }
     }
    else
     {
      S1OUT[0]=1;
      goto US;
    }
  }
  else
  {
    if(S2IN[1] == 1)
    {
      if(S1IN[0] == 1)
      {
        if(S1IN[2] ==1)
        {
          S2OUT[0] =1;
        }
        else
        {
          S1OUT[1] =1;
        }
      }
      else if (S1IN[2] ==1)
      {
       S1OUT[0] =1;
       S2OUT[0] =1;
      }
     else
     {
      S1OUT[0] =1;
     }
    }
    else
    {
      S2OUT[0]=1;
      if(S1IN[0] ==0)
      {
        S1OUT[0] =1;
      }
    }
  } 


Send1;
delay(10);
Send2;

}

void Request1()                                                                
{
  Wire.requestFrom(address, 3);                                             //error here
  byte index=0;
  while(Wire.available() > 0 && index < 3)
    {
      S1IN[index] = Wire.read();
      index++;
    }
}

void Request2()                                                                    
{
  Wire.requestFrom(address2, 2);                                 //and error here
  byte index=0;
  while(Wire.available() > 0 && index < 2)
    {
      S2IN[index] = Wire.read();
      index++;
    }
}
  
int Usensing()
{
}

void Send1()
{
  Wire.beginTransmission(1);
  Wire.write(S1OUT, 2);
  Wire.endTransmission();
}

void Send2()
{
  Wire.beginTransmission(2);
  Wire.write(S2OUT, 2);
  Wire.endTransmission();
}

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

#define address = 1

Lose the "="

 goto US;

Lose the "goto"

Send1;

Add some () paretheseses.

See how easy it is to find problems when you follow the rules and post code?

heh, shame on me... :stuck_out_tongue:

Lose the "goto"

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.

AWOL:
It isn't clear to me what the logic is, but a "so..while" or a "while" loop may be a better choice.

so..while?

Riva:

AWOL:
It isn't clear to me what the logic is, but a "so..while" or a "while" loop may be a better choice.

so..while?

'd' is right next to 's' on the keyboard.

It's even closer when you have fat fingers and a small touchscreen :frowning:

Arrch:
'd' is right next to 's' on the keyboard.

I realise this. :wink: So is 'f', maybe we can have a new looping structure called fo..bar

maybe we can have a new looping structure called fo..bar

That's fu-bar, and I've seen plenty of instances of that structure.

PaulS:

maybe we can have a new looping structure called fo..bar

That's fu-bar, and I've seen plenty of instances of that structure.

I really wanted to say foo...bar but figured the extra o on top of the mistyped s was a step to far. :slight_smile: