I’m dying here. Can anybody tell me why my bumper switches are pushed (it says so in the terminal window) but it doesn’t execute my else statement. It executes the else with the ultrasonic sensor but not the bumpers, why?
#include “UserAPI.h”
int Ultrasonic;
int loop = 1;
int Bumper1 = 1;
int Bumper2 = 1;
void main ( void )
{
Wait ( 2000 ) ;
while ( loop == 1 )
{
StartUltrasonic ( 1 , 11 ) ;
Ultrasonic = GetUltrasonic ( 1 , 11 ) ;
PrintToScreen ( “ultrasonic =%d\n” , (int)Ultrasonic ) ;
Bumper1 = GetDigitalInput ( 5 ) ;
PrintToScreen ( “Bumper = %d\n” , (int)Bumper1 ) ;
Bumper2 = GetDigitalInput ( 6 ) ;
PrintToScreen ( “Bumper = %d\n” , (int)Bumper2 ) ;
if ( Ultrasonic > 30 )
{
SetMotor ( 3 , 255 ) ;
SetMotor ( 2 , 0 ) ;
}
else
{
SetMotor ( 2 , 127 ) ;
SetMotor ( 3 , 127 ) ;
Wait ( 1000 ) ;
SetMotor ( 3 , 0 ) ;
SetMotor ( 2 , 255 ) ;
Wait ( 300 ) ;
SetMotor ( 3 , 0 ) ;
SetMotor ( 2 , 127 ) ;
Wait ( 1000 ) ;
}
if ( Bumper1 = 1 )
{
SetMotor ( 3 , 255 ) ;
SetMotor ( 2 , 0 ) ;
}
else
{
SetMotor ( 2 , 127 ) ;
SetMotor ( 3 , 127 ) ;
Wait ( 1000 ) ;
SetMotor ( 3 , 0 ) ;
SetMotor ( 2 , 255 ) ;
Wait ( 300 ) ;
SetMotor ( 3 , 0 ) ;
SetMotor ( 2 , 127 ) ;
Wait ( 1000 ) ;
}
if ( Bumper2 = 1 )
{
SetMotor ( 3 , 255 ) ;
SetMotor ( 2 , 0 ) ;
}
else
{
SetMotor ( 2 , 127 ) ;
SetMotor ( 3 , 127 ) ;
Wait ( 1000 ) ;
SetMotor ( 3 , 0 ) ;
SetMotor ( 2 , 255 ) ;
Wait ( 300 ) ;
SetMotor ( 3 , 0 ) ;
SetMotor ( 2 , 127 ) ;
Wait ( 1000 ) ;
}
StopUltrasonic ( 1 , 11 ) ;
}
}