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.

Serial_Output.ino 1.5KB

3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* FreqMeasureMulti - 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 <FreqMeasureMulti.h>
  7. // Measure 3 frequencies at the same time! :-)
  8. FreqMeasureMulti freq1;
  9. FreqMeasureMulti freq2;
  10. FreqMeasureMulti freq3;
  11. void setup() {
  12. Serial.begin(57600);
  13. while (!Serial) ; // wait for Arduino Serial Monitor
  14. delay(10);
  15. Serial.println("FreqMeasureMulti Begin");
  16. delay(10);
  17. freq1.begin(6);
  18. freq2.begin(9);
  19. freq3.begin(10);
  20. }
  21. float sum1=0, sum2=0, sum3=0;
  22. int count1=0, count2=0, count3=0;
  23. elapsedMillis timeout;
  24. void loop() {
  25. if (freq1.available()) {
  26. sum1 = sum1 + freq1.read();
  27. count1 = count1 + 1;
  28. }
  29. if (freq2.available()) {
  30. sum2 = sum2 + freq2.read();
  31. count2 = count2 + 1;
  32. }
  33. if (freq3.available()) {
  34. sum3 = sum3 + freq3.read();
  35. count3 = count3 + 1;
  36. }
  37. // print results every half second
  38. if (timeout > 500) {
  39. if (count1 > 0) {
  40. Serial.print(freq1.countToFrequency(sum1 / count1));
  41. } else {
  42. Serial.print("(no pulses)");
  43. }
  44. Serial.print(", ");
  45. if (count2 > 0) {
  46. Serial.print(freq2.countToFrequency(sum2 / count2));
  47. } else {
  48. Serial.print("(no pulses)");
  49. }
  50. Serial.print(", ");
  51. if (count3 > 0) {
  52. Serial.print(freq3.countToFrequency(sum3 / count3));
  53. } else {
  54. Serial.print("(no pulses)");
  55. }
  56. Serial.println();
  57. sum1 = 0;
  58. sum2 = 0;
  59. sum3 = 0;
  60. count1 = 0;
  61. count2 = 0;
  62. count3 = 0;
  63. timeout = 0;
  64. }
  65. }