View unanswered posts | View active topics It is currently Sun May 24, 2020 7:32 pm

 Page 1 of 1 [ 3 posts ]
 Print view Previous topic | Next topic
If statement repeating
Author Message
Rookie

Joined: Tue May 05, 2015 4:18 pm
Posts: 2
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

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
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
Rookie

Joined: Thu May 07, 2015 1:32 pm
Posts: 1
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
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
Display posts from previous:  Sort by
 Page 1 of 1 [ 3 posts ]

#### Who is online

Users browsing this forum: No registered users and 2 guests

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

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning