Skip to content

Instantly share code, notes, and snippets.

@sixstringsg
Last active May 20, 2020 00:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sixstringsg/80361a66a6651e104178699e3009aaa3 to your computer and use it in GitHub Desktop.
Save sixstringsg/80361a66a6651e104178699e3009aaa3 to your computer and use it in GitHub Desktop.
/* 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;
float engineRPM;
void setup() {
Serial.begin(57600);
while (!Serial) ; // wait for Arduino Serial Monitor
delay(10);
Serial.println("FreqMeasureMulti Begin");
delay(10);
freq1.begin(9);
}
void loop () {
int count = 6;
float raw = 0;
engineRPM = 0;
for (int i=0; i< count; i++) raw += freq1.read();
engineRPM = freq1.countToFrequency(raw / count) * 14.28;
Serial.print("Engine RPM: ");
Serial.println(engineRPM);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment