PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

Test.pde 1.9KB

3 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // FrequencyTimer2 Test
  2. // http://www.arduino.cc/playground/Code/FrequencyTimer2
  3. #include <FrequencyTimer2.h>
  4. void setup() {
  5. pinMode(FREQUENCYTIMER2_PIN, OUTPUT);
  6. Serial.begin(9600);
  7. delay(2);
  8. Serial.println("You can issue commands like:");
  9. Serial.println(" 12345p - set period to 12345 microseconds");
  10. Serial.println(" o - turn on a simple counter as the overflow function");
  11. Serial.println(" n - turn off the overflow function");
  12. Serial.println(" b - print the counter from the oveflow function");
  13. Serial.println();
  14. FrequencyTimer2::setPeriod(200);
  15. FrequencyTimer2::enable();
  16. }
  17. // variables shared between interrupt context and main program
  18. // context must be declared "volatile".
  19. volatile unsigned long burpCount = 0;
  20. void Burp(void) {
  21. burpCount++;
  22. }
  23. void loop() {
  24. static unsigned long v = 0;
  25. if ( Serial.available()) {
  26. char ch = Serial.read();
  27. switch(ch) {
  28. case '0'...'9':
  29. v = v * 10 + ch - '0';
  30. break;
  31. case 'p':
  32. FrequencyTimer2::setPeriod(v);
  33. Serial.print("set ");
  34. Serial.print((long)v, DEC);
  35. Serial.print(" = ");
  36. Serial.print((long)FrequencyTimer2::getPeriod(), DEC);
  37. Serial.println();
  38. v = 0;
  39. break;
  40. case 'r':
  41. Serial.print("period is ");
  42. Serial.println(FrequencyTimer2::getPeriod());
  43. break;
  44. case 'e':
  45. FrequencyTimer2::enable();
  46. break;
  47. case 'd':
  48. FrequencyTimer2::disable();
  49. break;
  50. case 'o':
  51. FrequencyTimer2::setOnOverflow(Burp);
  52. break;
  53. case 'n':
  54. FrequencyTimer2::setOnOverflow(0);
  55. break;
  56. case 'b':
  57. unsigned long count;
  58. noInterrupts(); // disable interrupts while reading the count
  59. count = burpCount; // so we don't accidentally read it while the
  60. interrupts(); // Burp() function is changing the value!
  61. Serial.println(count, DEC);
  62. break;
  63. }
  64. }
  65. }