Created
May 19, 2020 01:13
-
-
Save sixstringsg/6df5f7c07cc8d80d3e6e3af0808b698b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* FreqMeasureMulti - Example with serial output | |
* http://www.pjrc.com/teensy/td_libs_FreqMeasure.html | |
* | |
* This example code is in the public domain. | |
* | |
* I connected PIN 4 to PIN 6, PIN 4 to PIN 10 and PIN 3 to PIN 9 | |
* Results for Serial Output "n, 1463.99, 50.0000000000, 341520.84" | |
* | |
* Uncomment line 95 to see last value change | |
* | |
* There is some jitter in the 50 Hz signal which may be interupts | |
* but more likely just floating point precision | |
*/ | |
#include <FreqMeasureMulti.h> | |
// Measure 3 frequencies at the same time! :-) | |
FreqMeasureMulti freq1; | |
void setup() { | |
Serial.begin(57600); | |
while (!Serial) ; // wait for Arduino Serial Monitor | |
delay(10); | |
Serial.println("FreqMeasureMulti Begin"); | |
delay(10); | |
freq1.begin(6); | |
} | |
float sum1=0; | |
int count1=0; | |
uint8_t n=0; | |
elapsedMillis timeout; | |
void loop() { | |
if (freq1.available()) { | |
sum1 = sum1 + freq1.read(); | |
count1 = count1 + 1; | |
} | |
// print results every half second | |
if (timeout > 500) { | |
Serial.print(n); | |
Serial.print(", "); | |
if (count1 > 0) { | |
Serial.print(freq1.countToFrequency(sum1 / count1) * 14.28); | |
} else { | |
Serial.print("(no pulses)"); | |
} | |
Serial.println(); | |
sum1 = 0; | |
count1 = 0; | |
timeout = 0; | |
n = (n>99) ? 1 : n+1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment