PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
736B

  1. /* FreqMeasure - Example with LCD output
  2. * http://www.pjrc.com/teensy/td_libs_FreqMeasure.html
  3. *
  4. * This example code is in the public domain.
  5. */
  6. #include <FreqMeasure.h>
  7. #include <LiquidCrystal.h>
  8. LiquidCrystal lcd(5, 4, 3, 2, 1, 0);
  9. void setup() {
  10. Serial.begin(57600);
  11. lcd.begin(8, 2);
  12. lcd.print("Freq:");
  13. FreqMeasure.begin();
  14. }
  15. double sum=0;
  16. int count=0;
  17. void loop() {
  18. if (FreqMeasure.available()) {
  19. // average several reading together
  20. sum = sum + FreqMeasure.read();
  21. count = count + 1;
  22. if (count > 30) {
  23. float frequency = FreqMeasure.countToFrequency(sum / count);
  24. lcd.setCursor(0, 1);
  25. lcd.print(frequency);
  26. lcd.print(" ");
  27. sum = 0;
  28. count = 0;
  29. }
  30. }
  31. }