Equivalent of JoystickDigitalLatch in RobotC

Hello there,

So I am programming our pneumatics claw in RobotC which uses double acting pneumatics…

In easyC when I programmed the claw, I used JoystickDigitalLatch which allowed me to press the up button on channel 8 which would close the claw, then let go of the button and the claw will still be closed… If I then wanted to activate the claw again, all I would need to do is press the same button once…

What I’m wondering is that is there a equivalent of JoystickDigitalLatch in Robot C???

Thanks

I don’t think there is, however, you can use some basic logic and if statements to do this by your own code.

Something like this:

bool state = false//Starts with the pneumatic retracted
    if (VexRT[Btn6U]==1){          // if the Up button is pressed
        state=true; set state to false
    }
    if(VexRT[Btn6D]==1){           // if the Down button is pressed
        state=false; // set state to false
    }





    if (state){          // if state is true 
SensorValue[solenoid] = 1; // set the solenoid to out
    }
    else{          // otherwise
        SensorValue[solenoid] = 0; // keep it in
    }
    

This will allow the sensor to be changed at the press of the button. Don’t hold the button or it will flip in and out rapidly if there is too short of a delay in the loop.

That is essentially a toggle. Most things are built in in easy c, but the logic is really not complex. In robot c, I use toggle to do all of my program switching during driver control with toggles in a background task.

They are like this:



int toggle = 0;

task toggleloop ()
{
if (button pressed)
{
if (toggle == 0)
{
toggle =1;
while (button pressed) {}
}
else if (toggle == 1)
{
toggle =0;
while (button pressed) {}
}
}

task main ()
{
while (true)
{
pneumatic = toggle;
}
}

What a challenge typing codes with android device…