Hi everyone,
I have a project (it will use either Teensy 3.2 or LC, still TBD) where I need to output PWM for a about a second, and then possibly update the PWM value, wait another second, and so forth. I want to put the MCU into a sleep mode in order to save power during the wait period. Is this possible with Teensy? I did a quick test using the Snooze library, but it does not seem to work.
This is the code I tried:
This code is supposed to sweep the PWM output of pin 3 after a wait period of a second. It also blinks the onboard LED two times between transitions.
When I run this, I don't see the PWM rate updating. What I see instead is that pin 3 will be stuck to either high or low during the sleep. It seems like that pin gets stuck at whatever the PWM output was just as the MCU entered the sleep mode.
Any insights and tips are appreciated. Thank you and a happy new year!
I have a project (it will use either Teensy 3.2 or LC, still TBD) where I need to output PWM for a about a second, and then possibly update the PWM value, wait another second, and so forth. I want to put the MCU into a sleep mode in order to save power during the wait period. Is this possible with Teensy? I did a quick test using the Snooze library, but it does not seem to work.
This is the code I tried:
Code:
/*
AnalogWrite with snooze test
01/01/2017
*/
#include <Snooze.h>
SnoozeTimer timer;
SnoozeBlock config(timer);
void setup() {
pinMode(3, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
timer.setTimer(1000);
}
void loop() {
analogWrite(3, 32);
Snooze.hibernate(config);
analogWrite(3, 0);
blink();
analogWrite(3, 64);
Snooze.hibernate(config);
analogWrite(3, 0);
blink();
analogWrite(3, 128);
Snooze.hibernate(config);
analogWrite(3, 0);
blink();
analogWrite(3, 256);
Snooze.hibernate(config);
analogWrite(3, 0);
blink();
}
void blink() {
for (int i = 0; i < 2; i++) {
digitalWrite(LED_BUILTIN, HIGH);
delay(200);
digitalWrite(LED_BUILTIN, LOW);
delay(200);
}
}
This code is supposed to sweep the PWM output of pin 3 after a wait period of a second. It also blinks the onboard LED two times between transitions.
When I run this, I don't see the PWM rate updating. What I see instead is that pin 3 will be stuck to either high or low during the sleep. It seems like that pin gets stuck at whatever the PWM output was just as the MCU entered the sleep mode.
Any insights and tips are appreciated. Thank you and a happy new year!