# SleepySketch

A “normal” Arduino sketch spends most of its time awake, running code: the setup() function when first started, and then the loop() function for as long as the system has power. This is simple and straightforward, but not very power-friendly. A programmer can use the Arduino’s sleep modes explicitly, but this can be awkward for systems that are built up piecemeal, or from libraries that might want to run code on a regular basis: you’d have to put all this logic into loop() in some way.

SleepySketch is a library that inverts the usual form of a sketch. Instead of having code to manage sleep mode through the body of the program, a sleepy sketch defines fragments of code (“actors”) for different tasks and declares how they should be scheduled (once at the start, every 10 seconds, every 7 days, and so on). The library keeps the Arduino asleep for as long as possible, waking up on schedule to run actors. This maximises time spent asleep — and hence power saved — at the expense of making the Arduino more or less unresponsive while asleep. The trade-offs are quite delicate, and you can read more about them under our “power management” tag.

After unpacking the library, move the SleepySketch/ directory to the libraries/ sub-directory of your Arduino IDE installation.
See SleepySketch/doc/html/index.html for API documentation.
See SleepySketch/examples for some simple examples.