View Single Post
  #2   Spotlight this post!  
Unread 25-11-2009, 10:53
emmell's Avatar
emmell emmell is offline
Murphy was an Optimist!
AKA: Mannie Lowe
no team (Radbotics, RoboKnights, CircuitRunners, Oscar, and more...)
Team Role: Coach
 
Join Date: Dec 2005
Rookie Year: 2005
Location: Marietta, GA
Posts: 178
emmell is just really niceemmell is just really niceemmell is just really niceemmell is just really niceemmell is just really nice
Re: [FTC]: Buttons RobotC

Let's break this down step by step:

Quote:
Originally Posted by John_1102 View Post
if(joy2Btn(2) )
{
motor[motorF] = 100;
}
else
{
motor[motorF] = 0;
}
What the above "if" is saying is "If Button 2 on Joystick 2 is pushed, set power to motorF to 100%. Otherwise, set it to 0".

Quote:
Originally Posted by John_1102 View Post
if(joy2Btn(1) )
{
motor[motorF] = -100;
}
else
{
motor[motorF] = 0;
}
This one is saying "if Button 1 on Joystick 2 is pushed, set power to motorF to 100% in reverse. Otherwise, set it to 0".

The problem is not with the if (true) conditions, it's the else conditions that are conflicting with each other. If Button 1 is pressed, then button might or might be pressed, so motorF shouldn't go (the else conditions). Likewise for Button 2.

A better way to right the code is:
Code:
if (joy2Btn(1))
    {
    motor[motorF] = -100;
    }
else if (joy2Btn(2))
   {
    motor[motorF] = 100;
   }
else
    {
    motor[motorF] = 0;
    }
Since the target of the conditional test is the same resource (motorF), you'll have to keep the tests with the target in one condition.

Good luck!
__________________
Mannie Lowe
FIRST Program Manager - Center for Mathematics and Science Education - University of Mississippi
Mississippi FIRST Tech Challenge Affiliate Partner


Reply With Quote