Hello Vex World !
I’m currently trying to write code for a toggle switch, but can not get it to function correctly. I have tried different ways of writing it and all seem to fail.
The most recent is close to what I want, it has “GetJoystickDigital” retrieving to a “unsigned int” . This would set the value to “1” and a “if” statement would be met, this would cause it to go into a “while loop”. I can get the buttons to work and to change the speed, but this only works one time. I have a “else if” statement inside setting the flywheel speed to a certain speed. The “if” statement has a “break” in it but I can not get it to return.
My question is, how do I get it to get out of the “while loop” and back into the main code ?
–Thanks in advance.
(Here are some screenshots of the code.)

Keep reading the switch when in the while loop, ie. you need to keep updating the variable.
How would I go about doing so ?
Thanks for your speedy reply.
Lets back up a little, what exactly are you trying to do? Do you want to have something happen when holding the switch down or turn something on/off each time you press it?
Turn something on/off each time I press it.
I’m not going to write this out in EasyC as the concept is the same no matter what the language you are using. You need to detect the button being pressed, set a flag (that is, a variable that can be either 0 or 1) to indicate that that action has happened and then perhaps set another variable indicating that a different action needs to be performed. I know this has been asked before on the forum, there should be example code somewhere but here is a ROBOTC example.
int
GetJoystickButton()
{
return( vexRT Btn8U ] );
}
task main()
{
int MyButtonPressed;
int MyToggle = 0;
while(1)
{
if( GetJoystickButton() == 1 )
{
// pressed
// Was it pressed before
if( MyButtonPressed == 0 )
{
// we are now pressed
MyButtonPressed = 1;
// change 1 to 0, or 0 to 1
MyToggle = 1 - MyToggle;
}
}
else
{
// nor pressed
MyButtonPressed = 0;
}
if( MyToggle == 1 )
writeDebugStreamLine("toggle is On");
else
writeDebugStreamLine("toggle is Off");
// Long delay in this demo code only
wait1Msec(100);
}
}
Thank you for all of your time Mr.Pearman. After 15 minuets of programming and doing 1 proofread, I was able to get it to function correctly. Thanks again for your time. 