Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   joystick and relay programming plz help! (http://www.chiefdelphi.com/forums/showthread.php?t=73984)

programmr 09-02-2009 10:48

joystick and relay programming plz help!
 
i have

Joystick* thirdStick; //Joystick USB3
Relay* agitator; //Relay 1
Relay* agitator2; //Relay 1

thirdStick= new Joystick(3);
agitator = new Relay(1, agitator->kBothDirections);
agitator2 = new Relay(1, agitator2->kBothDirections);

if (thirdStick->GetRawButton(1)) {
agitator->Set(agitator2->kReverse);
}
else {
agitator->Set(agitator2->kOff);
}

i want to know how can i make the relay go forward and then go reverse based on either the x or y axis of the joystick: example:

x axis : left makes relay1 go rev, right makes relay1 go fwd

Please help! thank you!

pheadxdll 09-02-2009 12:08

Re: joystick and relay programming plz help!
 
You can use the GetX method from the Joystick class to return a float of the joystick from -1.0 to 1.0:

If you lean over half way to the left (on the x axis) it turns the relay reverse. The opposite then for the right direction and then off for in the middle.

Code:

if(thirdStick->GetX() < -0.5) // IF OVER HALF WAY LEANING TO THE LEFT
    agitator->Set(Relay::kReverse);
else if(thirdStick->GetX() > 0.5) // OVER HALF WAY TO THE RIGHT
    agitator->Set(Relay::kForward);
else // NEITHER/IN BETWEEN
    agitator->Set(Relay::kOff);


programmr 09-02-2009 13:22

Re: joystick and relay programming plz help!
 
thank you very much!


All times are GMT -5. The time now is 02:26.

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