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.

66 lines
1.3KB

  1. /***************************************
  2. This example shows how you can use the pwm
  3. while in 'sleep' mode, pwm will not work
  4. with deepSleep or hibernate because the
  5. pwm clocks are not active.
  6. Because 'sleep' mode puts the cpu speed
  7. at 2 MHz the FTM registers have to be
  8. updated for the 2 MHz cpu which this
  9. driver does.
  10. Supported Micros: T-LC/3.x
  11. Teensy 4.0 will not work with this sketch
  12. ****************************************/
  13. #include <Snooze.h>
  14. #include "SnoozeSleepPWM.h"
  15. SnoozeTimer timer;
  16. SnoozeSleepPWM pwm;// 'sleep' mode pwm driver
  17. // Connect the timer and pwm drivers
  18. SnoozeBlock config(timer, pwm);
  19. void setup() {
  20. pinMode(LED_BUILTIN, OUTPUT);
  21. timer.setTimer(30);
  22. delay(300);
  23. }
  24. void loop() {
  25. analogWrite(3, 32);
  26. // pin, value, resolution
  27. pwm.configure(3, 32, 8);
  28. Snooze.sleep(config);
  29. blink();
  30. analogWrite(3, 64);
  31. // pin, value, resolution
  32. pwm.configure(3, 64, 8);
  33. Snooze.sleep(config);
  34. blink();
  35. analogWrite(3, 128);
  36. // pin, value, resolution
  37. pwm.configure(3, 128, 8);
  38. Snooze.sleep(config);
  39. blink();
  40. analogWrite(3, 256);
  41. // pin, value, resolution
  42. pwm.configure(3, 256, 8);
  43. Snooze.sleep(config);
  44. blink();
  45. }
  46. void blink() {
  47. for (int i = 0; i < 2; i++) {
  48. digitalWrite(LED_BUILTIN, HIGH);
  49. delay(50);
  50. digitalWrite(LED_BUILTIN, LOW);
  51. delay(50);
  52. }
  53. }