ROBOTC.net forums
http://robotc.net/forums/

Getting out of an open loop
http://robotc.net/forums/viewtopic.php?f=11&t=6419
Page 1 of 1

Author:  hmgi [ Tue Jul 30, 2013 12:46 pm ]
Post subject:  Getting out of an open loop

I need to be able to push a button to exit my lines of code so the cycle below will stop. Can anyone help me with this?

Code:
task main()
{                                     //Program begins, insert code within curly braces
   int motorCount;
   motorCount=0;
   untilBump(bumperSwitch, 1000);
   while (motorCount<1000)
  {
     if (motorCount<1000)
    {
      startMotor(rightMotor, -63);
      wait(1);
      stopMotor(rightMotor);
      wait(2);
      startMotor(rightMotor, 63);
      wait(1);
      stopMotor(rightMotor);
      wait(2);
      motorCount=motorCount + 1;
     
     
     
    }
    else
    {
      stopMotor(rightMotor);
    }

Author:  Ernest3.14 [ Tue Jul 30, 2013 8:12 pm ]
Post subject:  Re: Getting out of an open loop

Make a new variable, `bButtonPressed`. In each iteration of your loop, check for a button press. If one happens, set `bButtonPressed` to `true`. Then, change the conditional of your while loop to this: `(motorCount<1000) || (bButtonPressed==true)`. This will end the while loop if either `motorCount` goes above 1000 or if the button is pressed.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/