Newb: Methods of Toggle Switch to Momentary Button for Gaming

Greetings! I’m brand new to electronics practically so bear with me. Right now I’m designing my box for flight sims to have a few on-off toggles which would great for immersion (engine on/off) rather than a momentary on-off-on toggle. Also I. Going to include buttons, momentary toggles, rotary encoders. However the issue is that games I play usually only read momentary button presses and I have a feeling that a standard on-off toggle set up normally would read as a constant input for. “On” and nothing for “off”. So the question is what would be the easiest way for a toggle to act as a momentary button with each pull of the switch ( ideally with each throw reading as a different output, like up is button 23 and down is button 24 )? I’m thinking of doing this with hardware getting an ON-On toggle with a relay and capacitor to make it a momentary button. The other option I saw on here was to code so that each change of switch state will read as an output. What complicates this is I am more than likely going to set up a button matrix and I’m not sure if I should leave them out and wire them separate. Any thoughts? Thanks!

Welcome to the forum.

How are you planning to communicate with the flight simulator software?

In general I would say that whatever you send to the simulator is not necessarily what you get as input. For example, you could detect a switch toggle, but send this as a momentary push button event.

No no no. Software easier here, def.

Switches that stay where you put them can be used in your button matrix as long as all the switches are diode isolated.

Google diode isolated matrix or start here

https://learn.sparkfun.com/tutorials/button-pad-hookup-guide/background

In your software you catch the fact that the switch has changed, and simulate that some button or other has been pressed.

It's not ideal, as a button that meant on/off wouldn't necessarily match the physical position of a toggle switch up/down. That may be a problem sometimes if everyone doesn't start on the same page so to speak.

Search these fora. I've contributed to this and similar problems recently

  toggle @alto777

I found this

which might be thought food, see if.

HTH

a7

This helps a lot! I looked into diode button matrix so I am glad that’s the right path. Are you referring to the Arduino IDE software or another program? I have found helpful button box code where I just need to change values and the code does the rest but I am not sure how the code you posted fits into it yet. That’s definitely a “future me”problem hah

Presumably you'll borrow some code to handle the buttons and everything. It is there, that software, where you would have an opportunity to get in between the physical buttons and whatever reports they make on up the line, and spoof anything.

I'm off to the beach, later I will look at the other places where I recall showing (or seeing) how to intercept and spoof in this circumstance.

Meanwhile, post any code you are working with so far so we can get an idea of where this surgery migth be performed.

And maybe 'splain again, or I should re-read about the why? The other places wanted to have a toggle swtich On/Off to used in place of a momentary push to go on, push to go off button.

You?

L8R

a7

The on-off toggle reports its state directly, if it's connected normally. There are several things you need to do, to translate its condition into momentary commands. Keep in mind, with the momentary toggle, you have a "virtual" toggle in software that maintains a useable working state (wipers on, or whatever).

  1. At initialization, read the toggle and set the virtual toggle to the same state
  2. Subsequently, if the state of the toggle changes, change the state of the virtual toggle.

All the code must follow from those premises.

#2 implies, if you have middleware that can only receive momentary (separate on/off) inputs, you also have:

If the physical toggle state changes, you must:
a) if the physical toggle is on and the virtual toggle is off, issue the interface "on" command
b) if the physical toggle is off and the virtual toggle is on, issue the interface "off" command

I agree with the previous responder, that you should share your code so it can be seen whether this middleware layer is necessary, or can be removed so you can link the toggle states directly to the software functionality.

That’s exactly what I need to happen. Now knowing whatI can do with the software, I can design the schematic and get a part list together. Once I’m further along in the building process, I’ll start working on the code and post what I have.

Thanks!

Confused. Are you proposing a hardware or software solution?

I thought I covered that in reply #7

I may be confused as well. From what alto said , it seemed they were sayin the easiest solution was to wire the toggle on-off normally to a diode button matrix with the rest of my buttons. and then in the code make it read each flip of the toggle as a momentary button press. Then I could map that button press to “Engine On/off” in the game. Did I understand that right?

Yes, and I gave you a detailed overview of the software solution requirements. You have just summarized the same approach.

You will have to deal with initial states, for example the flaps might be up when you start the sim, but the switch on your switch box has the flaps set to "down". So you have to perform some kind of synchronization of switches on the switch box, and virtual controls in the simulator.

That is a very good point. I’ll just have to be mindful of that. Like do a IRL pre-flight check

OK deeper a bit

but read in the thread, too.

The idea in there is that the switch has to look like a button that is pressed and released.

The hack I linked was to make note of the need to "unpress" a button and make that automatic the next event reported out. I think. Long time ago.

This still works:

https://wokwi.com/projects/317176715381047874

HTH

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.