Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Electric Imp Wake Pin Example
/*
* Electric Imp Wake Pin example code
*
* Requires any imp (but not relevant to imp005)
*
* Copyright 2020 Twilio
* License: MIT
*
*/
// Display how the imp awoke -- we'll be watching
local wakeReason = hardware.wakereason();
server.log(wakeReason == WAKEREASON_PIN ? "imp woken by wake pin" : "imp woken (but not by wake pin)");
// Set up the wake pin --
// We need to do this on every run *before* the
// imp goes into Deep Sleep
local impType = imp.info().type.slice(3);
local wakePin = hardware.pinW;
// Switch to a different pin from the default for certain imps
if (impType == "001" || impType == "002") wakePin = hardware.pin1;
if (impType == "005") {
server.log("The imp005 does not support Deep Sleep, or wake pin usage");
} else {
// Configure the wake pin for supporting imps
wakePin.configure(DIGITAL_IN_WAKEUP);
server.log("Wake pin selected and enabled... imp sleeping in 5 seconds");
// After 5 seconds, put the imp into Deep Sleep
imp.wakeup(5.0, function() {
imp.onidle(function() {
// Deep Sleep for 30 minutes -- from this point on,
// until the timer expires -- the imp can be woken by
// connecting a 3V3 pin to pin W
server.sleepfor(1800);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment