- Sun Feb 07, 2016 1:43 pm
#187941
Totally new to Arduino - don't even have my starter kit yet. But I do have a good background in VB programming. So before my stuff gets here, I'm trying to plot out my first sketch. I do have "Programming Arduino" by Simon Monk, and I'm going to work through that. But I didn't see this question answered in the book or in any forum yet.
My first project is going to be a metronome with the beat output set by tapping a footswitch. Because it's a foot-driven device, I wanted to stay with one switch -- I'd hate to step on a reset switch at the wrong time! I will need to capture the time at press (I'm assuming a High input) and the time the input goes back Low. As I see it now, I will need to choose one of three actions depending on the elapsed times. The IF / ELSE construct isn't the issue - it looks like I may have a conflict in the decisions.
-- If the switch is held down for more than 4 seconds (timeLow - timeHigh > 4000), then I need to call a Reset function.
-- If the time between the last full switch tap and this one is greater than 15 seconds (time High - timeLow > 15000), then I need to clear the previous beat and calculate a new one.
-- If neither of the above, then I'm working on a current beat calculation and need to go through the Loop().
The conflict seems to be in the first scenario: I can't wait 4 seconds every time the footswitch is tapped to see if I need to reset. The Loop commands will be processed in milliseconds, and I can anticipate beats (High inputs) up to about every 400 ms.
Is there a good way to handle this?? Or do I need to break down and add a reset switch?
Ed
My first project is going to be a metronome with the beat output set by tapping a footswitch. Because it's a foot-driven device, I wanted to stay with one switch -- I'd hate to step on a reset switch at the wrong time! I will need to capture the time at press (I'm assuming a High input) and the time the input goes back Low. As I see it now, I will need to choose one of three actions depending on the elapsed times. The IF / ELSE construct isn't the issue - it looks like I may have a conflict in the decisions.
-- If the switch is held down for more than 4 seconds (timeLow - timeHigh > 4000), then I need to call a Reset function.
-- If the time between the last full switch tap and this one is greater than 15 seconds (time High - timeLow > 15000), then I need to clear the previous beat and calculate a new one.
-- If neither of the above, then I'm working on a current beat calculation and need to go through the Loop().
The conflict seems to be in the first scenario: I can't wait 4 seconds every time the footswitch is tapped to see if I need to reset. The Loop commands will be processed in milliseconds, and I can anticipate beats (High inputs) up to about every 400 ms.
Is there a good way to handle this?? Or do I need to break down and add a reset switch?
Ed