Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   button control (http://www.chiefdelphi.com/forums/showthread.php?t=63437)

program1 06-02-2008 21:01

button control
 
im trying to activate moters for a certain amount of time with a press of a button on the joystick. how do you make a button code?

eaglesfan10 06-02-2008 21:17

Re: button control
 
You could set a flag and use a counter. It would probably look something like this:
static int flag = 0;
static int counter = 0;

if(button_pressed)
{
flag = 1;
}

if(flag && counter < some_number)
{
//your code
}
else
{
flag = 0;
counter = 0;
}
counter++;
I'm probably missing something, but that's the general idea. I think there are about 40 loop counts in one second.

Alexa Stott 06-02-2008 21:25

Re: button control
 
For each port on your OI, you have px_sw_top, px_sw_trig, px_sw_aux1, and px_sw_aux2 with "x" being the appropriate port number. Each of these corresponds with a button or a trigger on whatever joystick is plugged into the port (trig and top being the most obvious).

Your code should look something like this when you program the buttons:
Code:

if(button)
{
    doSomething();
}

...and so on from there.

Remember that buttons are digital devices; they are either on or off (1 or 0, respectively).

To control time, we've always simply defined a static unsigned int to 0 and incremented it for each loop of the processor. It takes a lot of playing around to get the values right. There are other ways to do this, as stated above, but that is one of your options.

Hopefully that helps. :)


All times are GMT -5. The time now is 23:51.

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