Potentiometer help - from ROBOTC forum

Most of us cannot port in the official forums so I reposted your question here. The general idea will be to limit the control value that you send to the motor when trying to go beyond the potentiometer value, something like this.

#pragma config(Sensor, in1,    pot,            sensorPotentiometer)
#pragma config(Motor,  port1,           swerve,        tmotorVex393, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
    int drive;
    
    while(1)
        {
        // Get joystick if outside deadband
        if( abs( vexRT Ch1 ] ) > 10 )
            drive = vexRT Ch1 ];
        else
            drive = 0;
        
        // kill drive if pot value is large and joystick is positive
        // assumption here is that positive drive make the pot's value increase
        if( (SensorValue pot ] > 3508) && (drive > 0) )
            drive = 0;
        
        // now set the motor
        motor swerve ] = drive;
        
        wait1Msec(20);
        }
}
1 Like