SparkFun Forums 

Where electronics enthusiasts find answers.

For the discussion of Arduino related topics.
#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
#187944
Use a timer type library like this, http://playground.arduino.cc/Code/Timer
This cant be the only one, so poke around and find one you like.

Or use a hardware clock (RTC - real time clock) with an alarm feature like this: http://playground.arduino.cc/Main/RTC-PCF8563. This library is mine, which reminds me I kinda need to add the 'counter' feature, which would behave more like a timer. Anyway you can set an alarm time X seconds in the future, and wire the arduino to the interrupt pin, this pin will go HI when the alarm event occurs.

I wrote the PCF lib, but there are other(more popular) RTC chips and libs out there, so again, pick the one you like and fits your parameters.

Does anyone still do VB, I quit VB like 15 years ago. I suggest getting some good C and C++ references and tutorials.
Much more useful. Also PragmaticBookshelf has a great book on Testing Embedded Systems using Unit Test techniques.
This one: https://pragprog.com/book/jgade/test-dr ... embedded-c
#187945
Study the "blink without delay" example that comes with the Arduino IDE (you don't need to have an Arduino to install it). This will show you how to make decisions based on time, and not have the microcontroller bogged down with delays.

A post on the Arduino forum demonstrates how to do several things at the same time: http://forum.arduino.cc/index.php?topic=223286.0
#187952
Thank you both for the input!! I'll take a look at the posts and code (can't promise this weekend - Valentines and all that), and come back with any questions. That alarm clock idea sounds good, but no delays sounds good too.
Does anyone still do VB
Actually, I do VBA, which is still very much needed in Excel and Access applications. I did make one actual VB project that I'm still using, although I need to convert it to Access when I get the time. And I've tried a few VBScript things at work, but I'm going to blame IT security for them not working! :wink:

Ed