See project's main page for further caveats, if you are not already familiar with them.
There are many ways to "skin a cat" and we are open to alternative approaches. For instance, a program could be built to polling, in Loop(), some digital pin, ad "things" could be done purely in software. This would have sundry limitations and would be a little kludgy... but might be suitable for some users, some tasks. Call it "the lazy approach". The "proper" way to do something like this would use a hardware interrupt approach. Call this the "serious approach"
2011 Jan 8: (WEP) The initial "frequency counter" code hooks interrupt 0 on digital pin 2, sets a flag, and then returns. The frequency measured by Arduino agrees pretty well with my scope.
This ISR "set flag and return" is due to attachInterrupt(interrupt, function, mode)
Quote: Inside the attached function, delay() won't work and the value returned by millis() will not increment. Serial data received while in the function may be lost. You should declare as volatile any variables that you modify within the attached function.
The easy ways to count frequency depend on pulseIn() with millis() or micros(), so I elected to have the interrupt to just set flag "dataComingIn" (and a LED) and return, this minimizes the disruption of timers and serial, and gives other code access to all the time functions.
Right now the demo idles in the main Loop() until some pulses trigger the ISR. The ISR sets the flag, turns on a LED (for development) and returns. Code in Loop() calls countFrequency() when the flag is set, then afterward clears the flag and turns off the LED. countFrequency() sets a start time-hack in millis(), loops thru 100 pulses with pulseIn(), and then hacks the stop time and returns kHz as a float(). Floating math is costly, so today I'm going to change to return an int() in Hz.
Precision is about 10 Hz, or rather the inverse number of millis() in 100 pulses. More pulses would be better, right now accuracy and precision are plenty good to just "drive on" with development, we can sharpen our pencils later.
Also my prototype code does not gracefully turn loose and return control to void Loop() after the first activation, but that's going to get ironed out today. Will also post some prototype code here and however our Dirt Cheap Dumb Webmaster deems fit.
The ultimate goal is code newbies can use to get top level functionality like "Node 3 Sensor 2 is 64 degrees F" or "Node 4 Switch 1 just opened" without having to delve into ISR and such. If this is you, we have nothing ready for you yet, just let us know who you are and be patient... :-)
2011 Jan 8: (TKB) I'd jotted down notes on a possible "lazy" answer. At some later date, I wrote up , be it from a DCDW or other source.