Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: Using Teensy to Convert a Toggle Switch to a Momentary?

  1. #1
    Junior Member
    Join Date
    May 2017
    Posts
    2

    Using Teensy to Convert a Toggle Switch to a Momentary?

    I recently ran across this article on the web:

    http://www.instructables.com/id/Lets...me-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

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    10,081
    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
    }

    // ...

    }

  3. #3
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,906
    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 by GremlinWrangler; 05-13-2017 at 10:07 AM.

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,787
    Quote Originally Posted by Tchail View Post
    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.

  5. #5
    Junior Member
    Join Date
    May 2017
    Posts
    2
    Hello Everyone,

    Thanks for the replies!

    This gives me a place to start.

    I have much to learn!

    -Tom

  6. #6
    Junior Member
    Join Date
    Nov 2018
    Posts
    16

    momentary to toggle switch

    Quote Originally Posted by PaulStoffregen View Post
    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •