Hello all,
I am new to the arduino scene and have come to a grinding halt on my project. I am using the library FreqMeasure and am trying to detect 0 (zero) when there is no signal. Reading from the PJRC website it says"Zero Handling
Because FreqMeasure works on a per-cycle time frame, it is impossible to directly measure zero frequency. When displaying frequency, such as the LCD_Output example, if the input frequency stops, the most recent measurement will remain on the display.
To detect zero, a timeout must be implemented. On simple approach would be to record the millis() time when FreqMeasure.available() returns true. When it returns false, check if too much time as elapsed and update the output to show zero."
With that in mind I have been playing around with the millis(). With no luck yet.
/* FreqCount - Example with serial output
* http://www.pjrc.com/teensy/td_libs_FreqCount.html
*
* This example code is in the public domain.
*/
unsigned long currentMillis;
unsigned long previousMillis = 0;
const long interval = 1000;
#include <FreqMeasure.h>
void setup() {
Serial.begin(57600);
FreqMeasure.begin();
}
double sum = 0;
int count = 0;
void loop() {
if (FreqMeasure.available() == 0) {
currentMillis = millis();
}
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
Serial.println("0");
}
else if (FreqMeasure.available()) {
// average several reading together
sum = sum + FreqMeasure.read();
count = count + 1;
if (count > 30) {
float frequency = FreqMeasure.countToFrequency(sum / count);
Serial.println(frequency);
sum = 0;
count = 0;
}
}
}
As you can see this is how its not done. I am trying to understand how to implement the use of the millis() If anyone could shed some light for me would be awesome. Thank you. Ray