View Single Post
  #3   Spotlight this post!  
Unread 25-11-2009, 19:13
JohnFogarty's Avatar
JohnFogarty JohnFogarty is offline
Trapped under a pile of MECANUMS :P
AKA: @doctorfogarty
FTC #11444 (Garnet Squadron) & FRC#1102 (M'Aiken Magic)
Team Role: Mentor
 
Join Date: Aug 2009
Rookie Year: 2006
Location: SC
Posts: 1,573
JohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond repute
Re: [FTC]: Buttons RobotC

Quote:
Originally Posted by emmell View Post
Let's break this down step by step:


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".


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!
Thanks this worked perfectly
__________________
John Fogarty
2010 FTC World Championship Winner & 2013-2014 FRC Orlando Regional Winner
Mentor FRC Team 1102 M'Aiken Magic
"Head Bot Coach" FTC Team 11444 Garnet Squadron
Former Student & Mentor FLL 1102, FTC 1102 & FTC 3864, FRC 1772, FRC 5632
2013 FTC World Championship Guest Speaker
Reply With Quote