|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Joystick Button Press
I am trying to accomplish a simple button task. When someone pushes a button I want it to keep doing the action (IE In this case "Relay Forward" & "Relay Reverse") until the microswitch is activated. Right now it stops as soon as you release the button.
What the code looks like right now is this Code:
if button1 == 1 & microswitch1 = 0 Relay Forward else if button2 == 1 & microswitch2 = 0 Relay Reverse else Relay Off |
|
#2
|
||||
|
||||
|
Re: Joystick Button Press
Quote:
... loop//your while loop .. if (button1 ==1 && !(microswitch1==1))//if button1 pressed and microsw ! pressed dir=1; else if (button2==1 && !(microswitch2==1))//if button2 pressed and microsw ! pressed dir=-1; else if (microswitch1 ==1 || microswitch2 ==1)//if microsw pressed dir=0; //otherwise do nothing to the value relay.Set((float)dir);//set the new (or old )value ... end loop ... |
|
#3
|
|||||
|
|||||
|
Re: Joystick Button Press
Quote:
Code:
if (button1 == 1 && microswitch1 == 0) Relay Forward else if (button2 == 1 && microswitch2 == 0) Relay Reverse else (0 == microswitch1 || 0 == microswitch2) Relay Off It is a best practice to write the statement 0 == microswitch so the compiler can catch the mistake (0=microswitch is an error) Also it is better to use a logial and (&&) rather than a bitwise and (&) since the bitwise and will not work in all situations (2 & 1 =false) Last edited by The Lucas : 06-03-2009 at 21:30. Reason: I didnt notice he wanted latching |
|
#4
|
|||
|
|||
|
Re: Joystick Button Press
Im aware of the proper syntax but I probably should have said it was more of a "Pseudo-Code"
|
|
#5
|
|||
|
|||
|
Re: Joystick Button Press
Code:
flipperdoor->Set(Relay::flipperset); |
|
#6
|
|||||
|
|||||
|
Re: Joystick Button Press
Quote:
Code:
flipperdoor->Set(Relay::kForward); Code:
flipperdoor->Set(Relay::kReverse); Code:
flipperdoor->Set(Relay::kOff); |
|
#7
|
|||
|
|||
|
Re: Joystick Button Press
What I believe I am trying to accomplish is setting it outside of the loop. So basically store a variable and set it to that variable later.
Initial Decleration of flipperset (unsure if that will work) Code:
Relay::Value flipperset; Code:
flipperset = Relay::kOff; Code:
if (m_leftStick->GetRawButton(5) == 1 && flipperdoorright->Get() == 0 ) {
flipperset = Relay::kForward;
} else if (m_leftStick->GetRawButton(4) == 1 && flipperdoorleft->Get() == 0 ){
flipperset = Relay::kReverse;
} else if (flipperdoorleft->Get() == 1 || flipperdoorright->Get() == 1) {
flipperset = Relay::kOff;
}
Code:
flipperdoor->Set(flipperset); |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| joystick button | furiousgeorge | Programming | 5 | 07-02-2009 15:57 |
| Intelitek Loader Press PRGM Button Fail | ttldomination | VEX | 1 | 25-02-2008 19:36 |
| Joystick Hat button | ten3brousone | Programming | 8 | 20-02-2005 13:31 |
| Joystick Button Deference | cibressus53 | Electrical | 3 | 01-11-2004 09:38 |
| Can a student Coach press the Stop Button | archiver | 2001 | 3 | 24-06-2002 02:39 |