bansari18
Posts: 21
Joined: Tue Mar 07, 2017 1:04 pm

check multiple buttons at same time pressed

Tue May 02, 2017 8:20 am

Hello,
I am using 10 buttons and among them I want to do some thing if only one button is pressed, some other task when any 2 buttons are pressed at a same time, and some other task when any 3 buttons are pressed. I am using node js for it. And using onoff module of npm. Any help how to do it.
Thanks in Advance.

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: check multiple buttons at same time pressed

Tue May 02, 2017 9:33 am

i have the idea that a simple
if ( A_pressed AND B_pressed ) ..
does not fit into the event program structure of node.js
possibly it would help others to play about this, if you show here your project
with the working 10 button read (app.js and package.json )
and as example a failed try to do the "multi button logic"

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: check multiple buttons at same time pressed

Tue May 02, 2017 9:45 am

Irrespective of the implementation language, my approach would be to read the status of each of the 10 buttons sequentially - but hopefully nearly 'instantaneously' - and store those statuses in some data structure such as a list or array. After that, counting the number of stored statuses for which "Pressed == TRUE" should be trivial, and that count gives you the basis for deciding the path your code subsequently takes.

If you really need to know about buttons literally being pressed 'at the same time' the sequential read of the gpio pins is probably not appropriate and you may need to think about some other way of connecting the buttons, via additional hardware, so that you can read all 10 statuses simultaneoulsy.

bansari18
Posts: 21
Joined: Tue Mar 07, 2017 1:04 pm

Re: check multiple buttons at same time pressed

Wed May 03, 2017 9:07 am

B.Goode wrote:Irrespective of the implementation language, my approach would be to read the status of each of the 10 buttons sequentially - but hopefully nearly 'instantaneously' - and store those statuses in some data structure such as a list or array. After that, counting the number of stored statuses for which "Pressed == TRUE" should be trivial, and that count gives you the basis for deciding the path your code subsequently takes.

If you really need to know about buttons literally being pressed 'at the same time' the sequential read of the gpio pins is probably not appropriate and you may need to think about some other way of connecting the buttons, via additional hardware, so that you can read all 10 statuses simultaneoulsy.

I have found the logic and it works better but a bit delayed.. but i am facing another big problem :( my gpios stopped working.. please check my new post. thank you...

Return to “Beginners”