robotc for Mindstorms **Error**:Undefined variable 'sonarSensor'. 'short' assumed

920 views Asked by At

This code should theoretically loop forever until the sonar sensor detects a value above 10 cm's but when I try to compile this program in gives me the message

Error:

Undefined variable 'sonarSensor'. 'short' assumed. I'm not sure why it does not see that sonar has been initialized.

Code:

//Program: Bridge Layer
//Date: 12/14/19

#pragma config(Sensor, S4, sonar, sensorSONAR); //Enable sonar to sensor pin 4 on the NXT

task main()
{
    int distance_in_cm = 10; //Initialize sensor value variable
    while(SensorValue[sonar] < distance_in_cm){ //Creat a loop checking if the sonar sensor ever sees a value above 10 cm's
        motor[motorB]= 50;  //Start motor B forwards att 50% power
        motor[motorC]= 50;  //Start motor C forwards att 50% power
    }
    motor[motorB]= 50;  //Stop motor B
    motor[motorC]= 50;  //Stop motor C
}
1

There are 1 answers

0
Minejosh80 On

Ok i'm good now i found that you must g through the configuration wizard and set the port and type of sensor for sonar. Thank you for the help.