Forbids comparison between pointer and integer!

In plain english i’m trying to test if my ultrasonic distance sensor is within range - if it is, I want to test my photocells and go in the direction of more light, if not I want to continue forward, but I keep getting the “Forbids comparison between pointer and integer” error!

// Control pins for the right half of the H-bridge
const int enable2 = 9; // PWM pin for speed control
const int in3 = 8;
const int in4 = 7;

//other half
const int enable1 = 6; // PWM pin for speed control
const int in1 = 4;
const int in2 = 2;

// ultrasonic distance measuring sensor
const int trigPin = 12;
const int echoPin = 11;

// light sensors
const int leftLDR = A0;
const int rightLDR = A1;

void setup() {

  Serial.begin (9600);

  // pins for the ultrasonic distance measuring sensor
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

  // motors
  pinMode( enable1, OUTPUT);
  pinMode( in1, OUTPUT);
  pinMode( in2, OUTPUT);

  pinMode( enable2, OUTPUT);
  pinMode( in3, OUTPUT);
  pinMode( in4, OUTPUT);

  // Set the speed to 100, which is pretty slow
  analogWrite (enable1, 100);
  analogWrite (enable2, 100);
}

void loop() {

  long distance;

  distance = measureDistance();

  if (testUltraSensor == true) { 
    // Test that the sensor is working before continuing
    // Check LDR's 
  
      if (analogRead (leftLDR) > analogRead (rightLDR)) {
        //if the left side has more light Turn left
        goLeft (100);
        
      } else () {
        //if the right side has more light Turn right
        goRight (100);
      }

  } else () {
    //keep going forward
    goFoward (100);
  }//end if statement
  
} // end of loop

  // go forward for a certain amount of time
  void goForward(int timeToMove) {

    // left motor
    digitalWrite (in1, HIGH);
    digitalWrite (in2, LOW);
    // Right motor
    digitalWrite (in3, LOW);
    digitalWrite (in4, HIGH);

    delay (timeToMove);
  }

  // turn left for a certain amount of time
  void goLeft(int timeToMove) {

    // left motor
    digitalWrite (in1, LOW);
    digitalWrite (in2, HIGH);
    // Right motor
    digitalWrite (in3, LOW);
    digitalWrite (in4, HIGH);

    delay (timeToMove);
  }

  // turn right for a certain amount of time
  void goRight(int timeToMove) {

    // left motor
    digitalWrite (in1, HIGH);
    digitalWrite (in2, LOW);
    //Right motor
    digitalWrite (in3, HIGH);
    digitalWrite (in4, LOW);

    delay (timeToMove);
  }

  // Take a measurement using the ultrasonic discance
  // measuring sensor and return the distance in cm
  // no error checking takes place

  long measureDistance() {
    long duration, distance;

    // measure how far anything is from us
    // send the pulse
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2); // low for 2 microseconds
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10); // high for 10 microseconds
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH); // measure the time to the echo
    distance = (duration / 2) / 29.1; // calculate the distance in cm
    return distance;
  }


  void testUltraSensor() {
    if (distance <= 200 || distance >= 50) { 
    // testing that the sensor in a 50-200 cm range of an obstruction
      Serial.print("I'm 50 cm or more away from something!!!");
    }else () {
      Serial.print("I'm not in range!");
    }
  }

You appear to have incorrectly posted a random snippet of unrelated code. Was that your intent?

Also, post ALL of your code,

  1. There is no error in that code
  2. We cant replicate it without the rest of the code
    Therefore, we cannot help you

Also, put your code in code tags by pressing the </> button

So that your code looks like this

Gotcha! Will fix

void testUltraSensor()

This function returns nothing, hence the "void"

Therefore,

if (testUltraSensor == true)

This does not work, you are asking if nothing is equal to true... See answers below as to why

  if (testUltraSensor == true) {

This will always be false because you are comparing the address of the testUltraSensor function with true, which is defined to have a value of 1.
Changing it to this:

  if (testUltraSensor() == true) {

won't get you far either because you've declared the testUltraSensor function to return void which means it returns nothing. The compiler will complain again.
If testUltraSensor is supposed to return a true or false value, fix it up so that it does. If it is supposed to be void, get rid of the if statement.

Pete

This does not make sense, you are asking if nothing is equal to true...

No. OP is asking if the function pointer is true. That is not a call to the function.

el_supremo:

  if (testUltraSensor == true) {

This will always be false because you are comparing the address of the testUltraSensor function with true, which is defined to have a value of 1.
Changing it to this:

  if (testUltraSensor() == true) {

won't get you far either because you've declared the testUltraSensor function to return void which means it returns nothing. The compiler will complain again.
If testUltraSensor is supposed to return a true or false value, fix it up so that it does. If it is supposed to be void, get rid of the if statement.

Pete

I am trying to return a true or false with the function, if I don't use void - what should I use?

if I don't use void - what should I use?

true and false are boolean values, aren't they?

bool (aka boolean) is a reasonable datatype…

bool testUltraSensor() 
{
  return( (distance >= 50) && (distance <= 200) );
}