Go to Post "well.. I think I underestimated the swine..." -Andy Baker - Joel J [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Spotlight this post!  
Unread 01-03-2016, 16:11
KrazyCarl92's Avatar
KrazyCarl92 KrazyCarl92 is offline
Registered User
AKA: Carl Springli
FRC #5811 (The BONDS)(EWCP)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2010
Location: Dayton, OH
Posts: 521
KrazyCarl92 has a reputation beyond reputeKrazyCarl92 has a reputation beyond reputeKrazyCarl92 has a reputation beyond reputeKrazyCarl92 has a reputation beyond reputeKrazyCarl92 has a reputation beyond reputeKrazyCarl92 has a reputation beyond reputeKrazyCarl92 has a reputation beyond reputeKrazyCarl92 has a reputation beyond reputeKrazyCarl92 has a reputation beyond reputeKrazyCarl92 has a reputation beyond reputeKrazyCarl92 has a reputation beyond repute
Re: Java Iterative-Robot: Toggle Buttons?

Quote:
Originally Posted by Fauge7 View Post
Code:
boolean buttonToggle = false;
if (button.isPressed()) {
  buttonToggle = !buttonToggle;
}

//code for using it:

if (buttonToggle) {
motor.setSpeed(someSpeed);
}
I do not believe this will work. What happens when your buttonToggle variable is false? You will need to add more to truly achieve toggle functionality.

Code:
boolean buttonToggle = false;
if (button.isPressed()) {
  buttonToggle = !buttonToggle;
}

//code for using it:

if (buttonToggle) {
motor.setSpeed(someSpeed);
} else {
motor.setSpeed(0);
}
Another reason this may experience an issue is that your code will start from the top of TeleopPeriodic every 20 ms or so. So if you hold down the button for 100 ms, your buttonToggle command (and therefore your motor output) will rapidly switch back and forth between true and false 5 times before letting go of the button. If you hold down the button for 80 ms? Switching back and forth 4 times and now you end up right where you started before you hit the button.

Edit: Follow BL0X3R's suggestion to achieve true toggling functionality.
__________________
[2017-present] FRC 0020 - The Rocketeers
[2016] FRC 5811 - BONDS Robotics
[2010-2015] FRC 0020 - The Rocketeers

Last edited by KrazyCarl92 : 01-03-2016 at 16:13. Reason: Added note.
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 01:45.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi