View unanswered posts | View active topics It is currently Sun Nov 17, 2019 8:49 am






Reply to topic  [ 3 posts ] 
If statement repeating 
Author Message
Rookie

Joined: Tue May 05, 2015 4:18 pm
Posts: 2
Post If statement repeating
I've been trying to figure out how to make a if statement not repeat and I cant seem to get it to work in the traditional method.

The scenario is I want to press down on a button on the VexRT remote and only have a sequence run once no matter how long I hold the button.

I was thinking using a variable that is changed at the end of the sequence would work but it seems to just skip over it.

Here's the code I have now

Code:
task main()
{
   
   while(1 == 1)
   {
      int f = 0;
      
      if(vexRT[Btn8R]==1 &&  f == 0)
   
      {
         
         motor[Sol1Fire] = 127;

         wait1Msec(500);

         motor[Sol1Fire] = 0;
         wait1Msec(5);
         motor[Sol1Reset] = 127;

         wait1Msec(500);

         motor[Sol1Reset] =  0;
         
         f = 1;
         
      
      }
   if (vexRT[Btn8R] == 0)
   {
      f = 0;
        }
   }
   }


Tue May 05, 2015 4:31 pm
Profile
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Re: If statement repeating
This might do the trick for you:
Code:
task main()
{
  while(1 == 1)
  {
    if(vexRT[Btn8R]==1)
    {
      motor[Sol1Fire] = 127;

      wait1Msec(500);

      motor[Sol1Fire] = 0;
      wait1Msec(5);
      motor[Sol1Reset] = 127;

      wait1Msec(500);

      motor[Sol1Reset] =  0;
     
      // wait until the button is no longer pressed
      while (vexRT[Btn8R]==1)
        sleep(10);
    }
  }
}

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Wed May 06, 2015 12:06 am
Profile WWW
Rookie

Joined: Thu May 07, 2015 1:32 pm
Posts: 1
Post Re: If statement repeating
A generic button handler requires consideration of four states and can be created by adding a state flag which can be 0 or 1.

Case 1. Button pressed and flag = 0
Set flag = 1
Do task
Case 2. Button Pressed and flag = 1
Do nothing
Case 3. Button Released and Flag = 1
Set Flag =0
Case 4. Button Released and Flag = 0
Do nothing


Mon May 11, 2015 2:07 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 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.