View unanswered posts | View active topics It is currently Mon Feb 08, 2016 7:23 pm

 Page 1 of 1 [ 6 posts ]
 Print view Previous topic | Next topic
Author Message
Rookie

Joined: Tue Apr 09, 2013 4:44 pm
Posts: 3

if(joy1Btn(4) == 1)
{
motor[motorB] = 25;
}
else
{
motor[motorB] = 0;
}
if(joy1Btn(3) == 1)
{
motor[motorB] = -25;
}
else
{
motor[motorB] = 0;
}

Thanks,
Coog1

Tue Apr 09, 2013 4:49 pm

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3618
Location: Rotterdam, The Netherlands
What's the paradox? What do you expect will happen when you press button 4 and 3 at the same time? What do you want to happen when you press those two buttons at once?

= Xander

_________________
| 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 Apr 10, 2013 3:50 am
Rookie

Joined: Tue Apr 09, 2013 4:44 pm
Posts: 3
The problem is that the first part of the program ( e.g. if(joy1Btn(4) == 1) {motor[motorB] = 25;}else{motor[motorB] = 0;} ) is conflicting with the second part ( e.g. if(joy1Btn(3) == 1){motor[motorB] = -25;}else{motor[motorB] = 0;} ) by telling motorB to not move when button 3 is not pressed, but hten when I press button 4 without pressing button 3 then the program needs to fight itself.

Wed Apr 10, 2013 4:13 pm

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3618
Location: Rotterdam, The Netherlands
So how will you fix that problem? What do you want to happen when both buttons are pressed? Nothing? Anything?

= Xander

_________________
| 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 Apr 10, 2013 4:31 pm
Rookie

Joined: Thu May 31, 2012 4:06 pm
Posts: 25
Location: Pittsburgh, Pa
One way to not have it switch from 25 to -25 rapidly is to have it do something else when both buttons are pushed at the same time:
 Code:if 1st button pressed and(&&) 2nd button pressed   do thing 3; (or nothing depending what you want to happen)else if 1st button pressed    do thing 1;else if 2nd button pressed   do thing 2;else   do thing 3;

Another way to prevent this is to check whether only one button is pushed:
 Code:if 1st button pressed and 2nd button not pressed      do thing 1;else if 2nd button pressed and 1st button not pressed   do thing 2;else    do thing 3;

And if you want to keep your code then try:
 Code:if 1st button pressed and 2nd button not pressed   do thing 1;else    do thing 3;if 2nd button pressed and 1st button not pressed   do thing 2;else    do thing 3;

There are a few ways to check that a button is not pressed.
Try:

 Code:joy1Btn(number) != 1orjoy1Btn(number) == 0

_________________
SHARP
Sarah Heinz Advanced Robotics Program

VEX 889A and FIRST 3260

Pittsburgh Champions Aerial Assist 2014
Pittsburgh and Buckeye Finalist Ultimate Ascent 2013
Toss Up Champions and Excellence-Pittsburgh
Toss Up Champions-Northwest Maryland VRC

Wed Apr 10, 2013 7:09 pm
Rookie

Joined: Tue Apr 09, 2013 4:44 pm
Posts: 3
Thanks so much Kevin, it worked like a dream.

Coog1

Sat Apr 13, 2013 11:08 am
Display posts from previous:  Sort by
 Page 1 of 1 [ 6 posts ]

#### Who is online

Users browsing this forum: No registered users and 1 guest

 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    2014 Robotics Academy Summer of Learning    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

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