View unanswered posts | View active topics It is currently Sun Aug 31, 2014 3:13 am






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

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?

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);
    }


Tue Jul 30, 2013 12:46 pm
Profile
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
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
Profile
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.