Reading Simultaneous Button Presses

Support for Arduino in combination with Air Manager and Air Player

Moderators: russ, Ralph

Message
Author
bdcurry
Posts: 20
Joined: Tue Feb 16, 2021 1:28 am

Reading Simultaneous Button Presses

#1 Post by bdcurry »

I've been working on a hardware chronometer input for the stock Xplane11 172. Thanks to help on this forum, the OAT/Volts function is working as it should with a hardware input. Since I use the simulator for training and fly a very similar real world 172, I'd like to get the hardware side as close as possible to the real world aircraft. On the real chronometer, the timer reset is done by hitting the "select" and "control" buttons simultaneously. In the xplane version, there's a "hidden" button between those that can be linked to a hardware input to reproduce this function. I've tried hooking up a couple of push buttons and writing some code (which is very crude) to replicate the simultaneous select/control button press to reset but so far no luck. Before I dig too deeply into this small detail, I was wondering if this is even possible -- can AM read two pushbuttons pushed at the same time (or nearly the same time within some time band) so I can send the reset command function back to Xplane? The fallback is to add a third button to the hardware chronometer for the reset function but it would be great if it could work the way it does in the real aircraft. Any insight appreciated.

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Reading Simultaneous Button Presses

#2 Post by Sling »

Absolutely possible. I incorporated this into my M803 chrono for Chuck on here quite a while back.

Depending on how your code is arranged it may be easier to incorporate this in the code or in hardware. In code is probably easier if you have already made the chrono.

Tony

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Reading Simultaneous Button Presses

#3 Post by jph »

Just for sh!ts and giggles ...., :)
IF you wanted to go the hardware route you could probably use a 2 input 'OR' gate - such as in the ubiquitous 74HC32. - this is a quad 2 input 'OR' gate CMOS logic IC.
Sounds complex, but really really is VERY VERY simple.
You use one of the 4 'OR' gates. Take the 2 existing switch inputs from the Arduino to the 2 input pins of any gate, then take the output of the gate to another Arduino pin set as a hardware button input and use this as its own button press (your 'third' button).
The truth table for the 2 input OR gate is - where A and B are inputs, and output Q are
image.png
image.png (3.38 KiB) Viewed 3849 times
Logic levels - 0 = low, 1 = high.

A B Q
0 0 0
0 1 1
1 0 1
1 1 1

So, only when the 2 existing buttons are pressed (connected to A and B) does the output Q go to 0 - logic low - and activate the signal for a button input on the arduino 'third' button.
The output 'Q' goes to another button input on the Arduino. - hence, your virtual third button
You may have to consider precedence of actions, but I don't see an issue in this case but I am 'thinking out loud' ;)
Using logic gates is a really good way of sorting many input functions when you do not have control over the main hardware as in a pre-programed Arduino. Of course, as tony says, I am sure there will be a relatively easy way of doing this in software, but that spoils the fun :mrgreen:
These logic gate building blocks are still around after nearly 50 years and still used in huge quantities today. There is a reason, they are amazingly simple and cheap, they are extremely reliable and bullet proof. For this use, you don't even need any external components.
Probably costs around 50 cents including a bit of Vero board. Again. just as a potential example of working around and with pre programmed hardware.
You could use NOR gates of course, at the expense of more gates. The NOR gate is amazing and the building block of most early computers. The whole Apollo guidance computer was built with NOR gates as they are the building block for any other logic gate. But that is another story. :D
Again, just 'postulating' as is my whim. :lol:

Oh, and I wanted to keep our patriarch and mentor Keith @Keith Baxter entertained with a 'reasonably' sized post haha :lol: :shock: ;) :geek:
Joe
Last edited by jph on Thu Mar 04, 2021 11:59 am, edited 1 time in total.
Joe. CISSP, MSc.

User avatar
Ralph
Posts: 7878
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Reading Simultaneous Button Presses

#4 Post by Ralph »

We want logic gates in Air Manager! :lol:

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Reading Simultaneous Button Presses

#5 Post by jph »

Ralph wrote: Thu Mar 04, 2021 11:42 am We want logic gates in Air Manager! :lol:
OH ! how I wish... A nice, easy to use FPGA :mrgreen:
When we reach the time that the host processor board has enough resources, certain aspects could certainly be built in.

On a serious note (for me), for people who are not familiar with this most basic stuff -and I mean that as it says, not they they don't understand ! , simply, that they are not familiar - major difference ! :!: - people should never be afraid of adding a few logic gates to their project as it is really easy, really cheap, and really effective. A bit of Boolean logic is all that is needed as Mr. Spock would say.
But, logic gates are the MOST basic level, and you can still get the most basic gates from any supplier to this day.
The ones to look for to cover our input voltage ranges are probably the 74 series, but go for the 74HCxx version.
To anyone not familiar, you are in for a treat. A bit of bread board, a few switches and buttons, an appropriate logic IC and an LED or two is all that is needed.
You can do things with a single 20 cent IC that would take an Arduino and a few lines of code to produce. Horses for courses etc.
LONG before the 16C84 PIC was available for hacking digital TV .. :shock: :? - we were using standard TTL or CMOS logic to do most things.
A reasonably good explanation of the functionality is -
https://www.youtube.com/watch?v=lXWpWNK ... 14presents
At 4 mins in, the OR gate is discussed, but for users not familiar with simple digital logic, then watch the whole thing.
This all sounds so complex, but it is really really THE simplest form of digital building blocks. almost Plug and Pray. ;)
there is nothing magical, you put it in a bit of breadboard or Vero board, add a few wires from inputs, then do something with the output.
Oh what fun you can have. :P - with your pants on...............
Joe
Joe. CISSP, MSc.

JackZ
Posts: 2262
Joined: Mon Feb 22, 2016 1:02 pm

Re: Reading Simultaneous Button Presses

#6 Post by JackZ »

Probably a dumb question, but using an AND Gate such as 7408 wouldn’t be in that case simpler instead of an OR?

The advantage I see is that the output would be high (+5V) only if BOTH A and B are pressed simultaneously according to the logic table, if I’m not mistaken. I tend to prefer an open circuit as default input, this circuit being closed only when needed.
But maybe that’s related to a potential bouncing issue?

Jacques
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Reading Simultaneous Button Presses

#7 Post by jph »

JackZ wrote: Thu Mar 04, 2021 1:30 pm Probably a dumb question, but using an AND Gate such as 7408 wouldn’t be in that case simpler instead of an OR?

The advantage I see is that the output would be high (+5V) only if BOTH A and B are pressed simultaneously according to the logic table, if I’m not mistaken. I tend to prefer an open circuit as default input, this circuit being closed only when needed.
But maybe that’s related to a potential bouncing issue?

Jacques
Hi Jacques
The AND would tend to be inverted. The input, in AM need to be pulled low, so the output of the gate at input low low (switch ON ON) needs to be EXCLUSIVELY pulled low when both inputs are low. The output of the OR would be fed into the input of an Arduino set with pullups engaged, hence an active low - switch is recognised as engaged then .. Apologies if my brain isn't working correctly ;) - just thinking out loud.
An AND would be active low when both buttons are pressed (as they go low) - ie, when both A and B are LOW. AND ALSO where A OR B is low - so no differentiation, as the output of the gate - being fed to an input of the Arduino sees a pull up (high)which is not what we want. We need a setup where the inputs being exclusively low low brings an output low.

edit - just to clarify for this discussion, the Arduino inputs have active pullups - hence the logic gate output is connected to the Arduino input - which even though it has the pull ups enabled - would still be forced high or low by the logic gate output. Again, due to this, the output of the gate of the logic circuit needs to go LOW only when the A B inputs are actually LOW. - not any combination hence the OR gate. - again, forgive me if my brain is confused, it would be nothing new at my age ;)
Joe
Joe. CISSP, MSc.

bdcurry
Posts: 20
Joined: Tue Feb 16, 2021 1:28 am

Re: Reading Simultaneous Button Presses

#8 Post by bdcurry »

Thanks for all the input. jph -- I'm intrigued by the hardware aspect and looking at these chips, you can purchase 5 of these for less than $2.00 so its a low cost way to go. Seems like an easy way to do it even for an electronics novice like myself. Sling --Regarding the code option, would it be possible to share the applicable portion of that code for this function? It would give my less than stellar code skills a leg up. I'm going to explore both approaches to gain some knowledge and I think it opens up some options in developing solutions for other parts of the avionics suite. Again, thanks for the assistance, much appreciated.

bdcurry
Posts: 20
Joined: Tue Feb 16, 2021 1:28 am

Re: Reading Simultaneous Button Presses

#9 Post by bdcurry »

Following up on the OR gate approach, in terms of wiring, it looks to me like I'd connect my push buttons to the Arduino as usual (one leg to an active pin, one leg to ground). I'd tap each leg prior to the push button contact (high side) for each switch and run those to the inputs of the OR gate on the 74HC32N (add VCC and GND for the 74HC32N as well). The output of the OR gate would go to another active pin on the Arduino (seen in AM as another switch input). Based on what I've read, I don't see the need for anything other than that? When both push buttons are pushed, both those circuits go to low, both OR gate inputs go to low resulting in the output of the OR gate being low and triggering the "3rd" button as "button pressed". From there, send the CMD back to Xplane to initiate the reset of the timer. Anything I missed? Thanks for the help!

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Reading Simultaneous Button Presses

#10 Post by Sling »

bdcurry,

You have it correct. The logic gate inputs are normally held high by the internal pull-ups in the Arduino. For the AM standard API button function the pull-ups are enabled so this works. This is not always the case so it’s best to check there are internal pull-ups.

The code variant works on a very similar concept. You store the state of each push button input and then whenever one is pressed you see if the other one’s state indicates if it is already pressed. When the result indicates they are both pressed you do the both pressed action.
Last edited by Sling on Fri Mar 05, 2021 12:43 pm, edited 1 time in total.

Post Reply