Skip to content

Instantly share code, notes, and snippets.

@ElectricImpSampleCode
Created October 7, 2020 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ElectricImpSampleCode/105eb21047e19d53412d75daaded4b77 to your computer and use it in GitHub Desktop.
Save ElectricImpSampleCode/105eb21047e19d53412d75daaded4b77 to your computer and use it in GitHub Desktop.
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