Thread: Help with Code
View Single Post
  #5   Spotlight this post!  
Unread 02-12-2016, 02:53 PM
TimTheGreat's Avatar
TimTheGreat TimTheGreat is offline
ArchdukeTim
FRC #1418 (Vae Victis)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2011
Location: Falls Church
Posts: 232
TimTheGreat has a spectacular aura aboutTimTheGreat has a spectacular aura aboutTimTheGreat has a spectacular aura about
Re: Help with Code

Quote:
Originally Posted by nlt5 View Post
I take that to mean that the button will have to be held down in order to turn the motors on. Is there a way that I can turn the motors on when I first press the button then turn them off when I press the button again?
Oh I see. So one way you can do it is set a boolean. Then check the boolean to see if it's true.

*Taken from Ether*
Code:
teleop_init
    button_previous = false;
...
teleop_periodic
    button_now = get_button(); // get the button state (pressed or not pressed)

    if (button_now && ! button_previous) // detect rising edge only

    runMotor = ! runMotor; // if rising edge, toggle the direction boolean

    button_previous = button_now; // save the button state for comparison in the next iteration

    if (runMotor)
        motor.set(1)
__________________
There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.



2012 - Gracious Professionalism - Greater DC
2014 - Regional Finalist - Virginia | Industrial Design - Virginia | Regional Finalist - Greater DC
2015 - Innovation in Control - Greater DC
2016 - District Event Winner - VAHAY | Innovation in Control - VAHAY | District Event Winner - MDBET | Industrial Design - MDBET | District Champion - CHCMP | Innovation in Control - CHCMP
Reply With Quote