Simple function bool not working?

I'm new to arduino, but I have some previous C programming experience, but I seem to struggle sending a simple bool state to a function's variable.

This is the code in question:

  approach(false, 70);
void approach(bool bReverse, int speed)
{
  int angle = map(speed, 0, 100, 0, 180);
  if(bReverse = false)
  {
      speedR = speed;
      speedL = speed;
      ESCL.write(angle);
      ESCR.write(angle);
  }
}

Nothing in the if statement is triggered, despite me sending a false bool to the function. I also tried using:
!= just to see if the opposite state is somehow being sent due to me missing something, but the code in the if condition is still not being triggered.

The function itself is being run correctly from this code, as it works when I put the ESCL.write(angle); outside the bool check, it's just the condition not working, wether I'm checking for true or false, how is this even possible?

  if(bReverse = false)

should be

  if(bReverse == false)

or

  if(not bReverse)

Cheers, there seems to be some syntax differences for me to get around that I'm not used to, guess I'll have to stick around the language documentation a lot more.

In C it's also == for equalliity and = for assignment. No change there :wink:

In cases like this, const correctness can help:

void approach(const bool bReverse, const int speed)
{
  int angle = map(speed, 0, 100, 0, 180);
  if(bReverse = false)
  {
      speedR = speed;
      speedL = speed;
      ESCL.write(angle);
      ESCR.write(angle);
  }
}

Will cause an error if you try to assign to it :slight_smile:

Btw, if speed is already signed, why not use the negative part for reverse?