Using Teensy to Convert a Toggle Switch to a Momentary?

Status
Not open for further replies.

Tchail

New member
I recently ran across this article on the web:

http://www.instructables.com/id/Lets-make-a-game-controller/

I'm a fan of flight simulators, and have recently started playing with the 2016 release of the Orbiter Space Flight Simulator. So it got me thinking about creating a basic control panel for one of the planes - The Delta Glider.

There's a fundamental problem, though, in wanting to use numerous toggle switches, rotating selector switches, slide and push button switches - Once the switch has been flipped it stays in an "always on" position. However, most functions in a simulator are activated using a keyboard press.

I'm thinking about using the Teensy 3.5 in this project. Is there a way using Teensy to convert the steady-on signal of a switch to a momentary pulse, and then ignore the signal from the switch until the next time it is flipped?

Although I'm not a programmer, I'm pretty good at hacking scripts.

Any help would be appreciated

-Tom
 
Something like:
int Last_x;
setup{
mode>pinx,output
Last_x = read(pinx)
}

loop{
int Test_x = read(pinx)

if ( Text_x != Last_x ) {
// detected a pinx TOGGLE - send a momentary indication
Last_x = Text_x
}

// ...

}
 
Note that this will give you a system that sends a key each time the switch is toggled, it won't give you 'up' for gear up 'down' for gear down behavior unless as part of pre flight you manually sync everything. The more complex sim interfaces support two way messages so you can send serial traffic to find system states and update things correctly. So my Kerbal Space Program panel can detect gear state via the KSPIO mod, and if it doesn't match the toggle position sends a keypress to make it so (plus some logic to stop it triggering every cycle). And as a bonus can have indicator lamps for things. X-plane has such a plugin, very good odds orbiter has one as well given the user base but haven't actually gone looking.

That said looking at the Teensy keyboard/joystick examples will get you most of the way to an input only controller fairly easily, and a basic controller you can play the game with is more fun than the ambitious one that's not finished yet.

edit:
http://www.orbiter-forum.com/forumdisplay.php?f=67
http://www.orbiter-forum.com/showthread.php?t=35156
but looks like there isn't a plug and play example in my 10 seconds of looking.
 
Last edited:
Is there a way using Teensy to convert the steady-on signal of a switch to a momentary pulse, and then ignore the signal from the switch until the next time it is flipped?

Yes, there are many ways. I highly recommend using the Bounce library. It does this very well and automatically handles the mechanical chatter.

Look at File > Examples > Teensy > USB_Keyboard > Buttons for an example.
 
momentary to toggle switch

Yes, there are many ways. I highly recommend using the Bounce library. It does this very well and automatically handles the mechanical chatter.

Look at File > Examples > Teensy > USB_Keyboard > Buttons for an example.

What about the opposite, making a momentary pushbutton to act like a toggle switch?
 
Status
Not open for further replies.
Back
Top