Hi all, I'm hoping to get some help writing code for a project I'm working on. Here's the gist of my setup and program requirements:
13 user buttons, each driving three independent switches for redundancy (therefore 39 individual digital inputs). I need to measure the time it takes for all three switches to be activated for any given button. Because it's impossible for all the switches to activate at once, I have a spec for debounce/staggered triggering time that all three have to fall into.
Avenues I've investigated so far have been Direct Port Manipulation and Interrupts.
DPM is proving difficult for me because the Due has some fundamental differences compared to other Arduino boards, so there's less info online about how to implement it the way I want to. I'm imagining this pseudo-code would work, though.
loop()
read all ports, write current state to variable1
wait for new current state != variable1, record time in micros() and save new current state to variable2
wait for new current state != variable2, record time in micros() and save new current state to variable3
wait for new current state != variable3, record time in micros() and save new current state to variable4
subtract recorded times from one another and deliver delays via serial.print.
Interrupts also seem like they could work, but I'm not sure if it would be easier or advantageous over DPM. I know the Due has interrupts tied to every digital pin, but I don't know if they can all be independent from one another. Any help would be appreciated!
I think it would be worth considering carefully whether the proposed redundancy would actually make the system any more reliable when the complexity of handling all that additional stuff is taken into account.
Your efforts might be better spent on other aspects of the program.
What is the probability of a single switch not registering?
How does that risk compare with other risks of equipment failure within your system?
Why not buy better quality switches?
Robin2:
I think it would be worth considering carefully whether the proposed redundancy would actually make the system any more reliable when the complexity of handling all that additional stuff is taken into account.
Your efforts might be better spent on other aspects of the program.
What is the probability of a single switch not registering?
How does that risk compare with other risks of equipment failure within your system?
Why not buy better quality switches?
...R
The redundancy is a requirement of my client (I'm a mechanical engineer by trade), so that's not something that will change. The purpose of this device is to simply test the delay between inputs, which is the result of mechanical design. The actual electronics will be handled by a different team.
PaulS:
This makes no sense, so I stopped reading here.
Why would you be taking buttons off of a shirt, and thinking you can use them to control the state of an input device?
Are you serious? A button is the part of an input device that a user interacts with. A switch is the part that makes the actual electrical connections. It's one button that drives three switches.
Whandall:
Really? I think there is a big difference between impossible and very unlikely.
It's actually incredibly common. Not as much on toggles as it is on push buttons. If you ever get a chance, try pressing a triple-redundant button in a fighter jet. You can hear each switch fire off one by one if you press slowly.
Robin2:
If this has anything to do with the military I don't want to have anything to do with it.
...R
Well luckily for you it does not, haha. I've just used those switches in my R&D and was referencing them as an example. I don't think the military would be particularly interested in using Arduinos...
Why not wire all three switches to a single Arduino pin so it does not matter which switch triggers the Arduino and write code that does not need to know anything about bouncing.
I presume you are NOT writing a system which depends on all 3 switches being ON in order to cause an event to happen.
Robin2:
Why not wire all three switches to a single Arduino pin so it does not matter which switch triggers the Arduino and write code that does not need to know anything about bouncing.
I presume you are NOT writing a system which depends on all 3 switches being ON in order to cause an event to happen.
...R
I am, actually. The entire purpose of this setup is to quantify the debounce and stagger between the switches in each button.
But through some experimentation I found that for loops and switch/cases were actually fast enough for my application, and I've got some code up and running perfectly. Thanks for everyone's help.