PDA

View Full Version : switch help for racing simulator



dirtdiver
01-01-2013, 10:17 PM
Hi Paul, im almost ready with my racing sim. -steering, clutch, gas, h-shifter..it ready

All i need to do is figure out how to make the program so that when i flip switch it sends a pulls on each change (in other word behave like a pushbutton) couse games dont support a switch function , just pushbutton.

i need to send a pulls when its turned on and then send that same pulls when the switch is flipped to "off" .
Can you help me whit that?
Thanks in advance!!!

dirtdiver
01-01-2013, 10:46 PM
Just did it! For those of you wondering the same here is how you do it

if (button5.fallingEdge()) {
Joystick.button(12, 1);
delay(50);
Joystick.button(12, 0);
}

if (button5.risingEdge()) {
Joystick.button(12, 1);
delay(50);
Joystick.button(12, 0);
}

dirtdiver
01-01-2013, 11:54 PM
OH MAAN, just encountered another problem
my switches are fine -working , then i connected the pushbuttons and its 100% the same code but it doesnt press a joystick button (testing with joy.cpl)
hte buttons are connected correctly (tested with digital read trough serial port)

Bounce button6 = Bounce(6, 10);
Bounce button7 = Bounce(7, 10);
Bounce button8 = Bounce(8, 10);
Bounce button9 = Bounce(9, 10);
Bounce button10 = Bounce(10, 10);
Bounce button11 = Bounce(11, 10);
Bounce button12 = Bounce(12, 10);


pinMode(6, INPUT_PULLUP); // Teensy++ LED, may need 1k resistor pullup
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);

button6.update();
button7.update();
button8.update();
button9.update();
button10.update();
button11.update();
button12.update();

if (button6.fallingEdge()) {
Joystick.button(13, 1);
}
if (button7.fallingEdge()) {
Joystick.button(14, 1);
}
if (button8.fallingEdge()) {
Joystick.button(15, 1);
}
if (button9.fallingEdge()) {
Joystick.button(16, 1);
}
if (button10.fallingEdge()) {
Joystick.button(17, 1);
}
if (button11.fallingEdge()) {
Joystick.button(18, 1);
}
if (button12.fallingEdge()) {
Joystick.button(19, 1);
}

//

if (button6.fallingEdge()) {
Joystick.button(13, 0);
}
if (button7.fallingEdge()) {
Joystick.button(14, 0);
}
if (button8.fallingEdge()) {
Joystick.button(15, 0);
}
if (button9.fallingEdge()) {
Joystick.button(16, 0);
}
if (button10.fallingEdge()) {
Joystick.button(17, 0);
}
if (button11.fallingEdge()) {
Joystick.button(18, 0);
}
if (button12.fallingEdge()) {
Joystick.button(19, 0);
}

I just cant seem to find the mistake or reason for this not to work!
Any help is greatly appreciated!

Magnethead494
01-02-2013, 12:39 AM
So are you using momentary toggle, standard toggles, or pushbuttons? Originally you said toggle, now you say pushbutton?

Since you're turning the output on with a falling edge, I assuming the switches are between the input pin and ground.

Examining, so you want the output on at press, then toggle it on next press. IOW, you're using pushbuttons where Ideally you'd have a standard toggle switch.

Hook a scope onto the outputs. I think you need to put the if (xx.fE()) inside if (xx.update()) statements so that you don't get multiple triggers. When you push the button, I believe that increments update (Which should decrement on call) and increments the proper edge. But I have to wonder if the compiler wil combine the statements, IE it's turning it on then off in the same compiled (if (xx.fE()) statement. I don't know the least about compilers, but that's my hypothesis.

dirtdiver
01-02-2013, 12:52 AM
1st, thanks for the response!
i solved my switch problem, now the problem is with a standard pushbutton- its really simple - on press of the button a joystick button is also pressed, on release nothing happens. the code works fine just like that with the switches . for some reason it wont with the pusbuttons.What do you mean with "Hook a scope onto the outputs" and also what will (xx.fE()) do?

Magnethead494
01-02-2013, 07:14 AM
1st, thanks for the response!
i solved my switch problem, now the problem is with a standard pushbutton- its really simple - on press of the button a joystick button is also pressed, on release nothing happens. the code works fine just like that with the switches . for some reason it wont with the pusbuttons.What do you mean with "Hook a scope onto the outputs" and also what will (xx.fE()) do?

So when is the joystick button supposed to be released? The next time you press the button? never? After a set amount of time?

I'm using shorthand. xx.FE() for fallingEdge.

dirtdiver
01-02-2013, 08:20 AM
the button is pressed and released in a meter of 100-200 ms maybe.its released right after its being pressed

PaulStoffregen
01-02-2013, 03:42 PM
In message #3 all the checks are fallingEdge(). Change half to risingEdge().

dirtdiver
01-02-2013, 04:57 PM
oh man..after i saw your post i looked at my feet. I guess thats the kind of mistakes you make when you are making a program till 5 in the morning
thanks for the help!!!

Magnethead494
01-02-2013, 11:37 PM
oh man..after i saw your post i looked at my feet. I guess thats the kind of mistakes you make when you are making a program till 5 in the morning
thanks for the help!!!

Happens to the best of us.

PaulStoffregen
01-02-2013, 11:39 PM
I've actually done exactly the same thing. That's how I recognize it. ;)

dirtdiver
01-03-2013, 12:22 AM
:D i feel better now!