PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

30 lines
583B

  1. /* FreqMeasure - Example with serial 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. void setup() {
  8. Serial.begin(57600);
  9. FreqMeasure.begin();
  10. }
  11. double sum=0;
  12. int count=0;
  13. void loop() {
  14. if (FreqMeasure.available()) {
  15. // average several reading together
  16. sum = sum + FreqMeasure.read();
  17. count = count + 1;
  18. if (count > 30) {
  19. float frequency = FreqMeasure.countToFrequency(sum / count);
  20. Serial.println(frequency);
  21. sum = 0;
  22. count = 0;
  23. }
  24. }
  25. }