View Single Post
  #12   Spotlight this post!  
Unread 23-01-2011, 20:01
basicxman basicxman is offline
Emily Horsman
FRC #2200 (MMRambotics)
Team Role: Programmer
 
Join Date: Oct 2007
Rookie Year: 2007
Location: Burlington, Ontario
Posts: 971
basicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant future
Send a message via AIM to basicxman Send a message via MSN to basicxman Send a message via Yahoo to basicxman
Re: Button programin C++

If you want it to toggle, (untested)

Code:
bool hasJoystickBeenClicked(Joystick &joystick, bool &prev, bool &cur) {
  prev = cur;
  cur  = joystick.GetTrigger();

  // Previous joystick value should be true (pressed trigger) and 
  // current one should be false (released trigger).
  return (prev && !cur) ? true : false;
}

void getMotorSpeed(float &speed, bool half) {
  return (half) ? speed / 2 : speed;
}

void toggleHalfSpeed(bool &half) {
  half = !half;
}

// ...

if (hasJoystickBeenClicked(joystick, prev, cur))
  toggleHalfSpeed(isHalfSpeed);

// ...

motor.Set(getMotorSpeed(speed, isHalfSpeed));
EDIT: More code.

Last edited by basicxman : 23-01-2011 at 20:07.
Reply With Quote