Snooze v6.3.9
Low power library for the Teensy LC/3.2/3.5/3.6/4.0 class microcontrollers.
Teensy 4.0 v2 update!
This is a maintenance update because of a change in the new class structure which the main Snooze Class is now decoupled from the Drivers and HAL. Now sleep*, deepSleepand hibernate work with T_LC and 3.x. Now the T_LC/36 Driver "Touch" works in "sleep" mode.
- not all drivers work in "sleep" yet.
Example usage:
#include <Snooze.h>
// Load drivers
SnoozeDigital digital;
// install drivers to a SnoozeBlock
SnoozeBlock config(digital);
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
/********************************************************
Define digital pins for waking the teensy up. This
combines pinMode and attachInterrupt in one function.
Teensy 4.0
Digtal pins: all pins
Teensy 3.x
Digital pins: 2,4,6,7,9,10,11,13,16,21,22,26,30,33
Teensy LC
Digital pins: 2,6,7,9,10,11,16,21,22
********************************************************/
digital.pinMode(21, INPUT_PULLUP, RISING);//pin, mode, type
digital.pinMode(22, INPUT_PULLUP, RISING);//pin, mode, type
}
void loop() {
/********************************************************
feed the sleep function its wakeup parameters. Then go
to deepSleep.
********************************************************/
int who = Snooze.deepSleep( config );// return module that woke processor
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
digitalWrite(LED_BUILTIN, LOW);
}
Current Divers:
- touch - Using the Kinetis touch module to wake your Teensy. (Teensy 3.5/4.0 does not have Touch)
- digital - Wake your Teensy with a RISING or FALLING event on a certain pin.
- timer - Use the Low Power timer in milliseconds T3.x/LC, seconds T4.x to wake your Teensy,
- alarm - Use the RTC clock to wake your Teensy.
- compare - Setup a voltage crossing to wake your Teensy.
- usbSerial - Does not wake the teensy it makes USB Serial play nice while using Snooze.
- audio - Allows the Audio library to work as normal after waking from sleep, does not wake the Teensy.
- spi - Configures the spi pins for low power, does not wake the teensy up.
Next we see the SnoozeBlock only has the timer and digital drivers installed. Even though the Touch driver is loaded it is not installed so it won't get called. In this example either the timer expires or the digital pin is lifted will wake the Teensy up.
#include <Snooze.h>
// Load drivers
SnoozeTouch touch;
SnoozeDigital digital;
SnoozeTimer timer;
// install drivers to a SnoozeBlock
SnoozeBlock config(timer, digital);
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
/********************************************************
* Set Low Power Timer wake up in milliseconds T3.x/LC,
* seconds T4.x.
********************************************************/
timer.setTimer(5000);// milliseconds
/********************************************************
* Define digital pins for waking the teensy up. This
* combines pinMode and attachInterrupt in one function.
*
* Teensy 4.0
* Digtal pins: all pins
*
* Teensy 3.x
* Digital pins: 2,4,6,7,9,10,11,13,16,21,22,26,30,33
*
* Teensy LC
* Digital pins: 2,6,7,9,10,11,16,21,22
********************************************************/
digital.pinMode(21, INPUT_PULLUP, RISING);//pin, mode, type
digital.pinMode(22, INPUT_PULLUP, RISING);//pin, mode, type
}
void loop() {
/********************************************************
* feed the sleep function its wakeup parameters. Then go
* to deepSleep.
********************************************************/
int who = Snooze.deepSleep( config );// return module that woke processor
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
digitalWrite(LED_BUILTIN, LOW);
}
Lets break out each part out so we can see what is going on here:
- Include the Snooze library header. This brings in Snooze, SnoozeBlock, HAL and HAL Driver Classes.
#include <Snooze.h>
- Next we load the drivers classes we want visible to install.
SnoozeTouch touch;
SnoozeDigital digital;
SnoozeTimer timer;
3. Here we install only the Timer and Digital drivers to the SnoozeBlock.
SnoozeBlock config(timer, digital);
4. Now we configure the Drivers, typically drivers have some way of changing certain parameters.
timer.setTimer(5000);// milliseconds
digital.pinMode(21, INPUT_PULLUP, RISING);//pin, mode, type
digital.pinMode(22, INPUT_PULLUP, RISING);//pin, mode, type
5. Lastly we supply the SnoozeBlock to whatever sleep function you want to use from the Snooze class. We still have the same three sleep modes
Snooze.sleep( config );
Snooze.deepSleep( config );
Snooze.hibernate( config );
Now that was easy enough lets take deeper look at the library structure.
As you can see Snooze library has only one Snooze Class but can have multiple SnoozeBlocks which have multiple Drivers. Referring to the first graphic Snooze is 3 Tier Class structure:
- Snooze Class
- SnoozeBlock Class
- Drivers Classes
This class is the top tier code for Snooze and handles the calling the low level code. There can only be one instance of this class and must defined globally. It has only three simple low power functions (sleep, deepSleep, hibernate) that take a SnoozeBlock argument. Here is a digram of the code flow for the Snooze class which is important to understand how this library works. Snooze Class:
...TODO Snooze Class code flow diagram.