View unanswered posts | View active topics It is currently Fri Sep 25, 2020 12:49 am

Reply to topic  [ 2 posts ] 
Getting out of an open loop 
Author Message

Joined: Tue Jul 30, 2013 12:42 pm
Posts: 1
Post 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?

task main()
{                                     //Program begins, insert code within curly braces
   int motorCount;
   untilBump(bumperSwitch, 1000);
   while (motorCount<1000)
     if (motorCount<1000)
      startMotor(rightMotor, -63);
      startMotor(rightMotor, 63);
      motorCount=motorCount + 1;

Tue Jul 30, 2013 12:46 pm
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 271
Location: Olympia, WA
Post 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.

FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

and also quadrotors. Quadrotors!

Tue Jul 30, 2013 8:12 pm
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.