Search code examples
cvariablesconditional-statementsexpressionlocal

Expected expression occurs in C


What I am doing here is, measuring 8 bit of IR sensor data. Here Reflectance_Read(time) returns the 8 bit IR sensor data in Binary form. Then taking the middle two sensors value, bit number 3 and 4 from the Data variable as Right and Left variable, I tried to return something like OffRoad, OnRoad etc.

#define OffRoad = 0x0
#define OffToLeft = 0x1
#define OffToRight = 0x2
#define OnRoad = 0x3
#define LeftCheck = 0x10
#define RightCheck = 0x08
uint8_t Reflectance_Center(uint32_t time){

    uint8_t Data;
    uint8_t Left, Right;
    Reflectance_Init();
    Data = Reflectance_Read(time);
    Left = Data&0x10;
    Right = Data&0x08;
    if(0){}
    else if(Left==LeftCheck && Right==RightCheck) return OnRoad;
    else if(Left==LeftCheck && Right!=RightCheck) return OffToRight;
    else if(Left!=LeftCheck && Right==RightCheck) return OffToLeft;
    else if(Left!=LeftCheck && Right!=RightCheck) return OffRoad;
    return 0;
}

But I got an error from else if(Left==LeftCheck && Right==RightCheck) return OnRoad; this line saying error #29: expected an expression. I can't figure it out what is causing the error.

#define OFFROAD 0x0
#define OFFTOLEFT 0x1
#define OFFTORIGHT 0x2
#define ONROAD 0x3
#define LEFTCHECK 0x10
#define RIGHTCHECK 0x08

I've changed my #define in the correct form. My Problem is Solved!


Solution

  • #define LeftCheck = 0x010;

    That syntax is incorrect (or well, at least it's probably not what you intend). Change it to
    #define Leftcheck 0x010

    Also applies to all other of your defines.