Skip to content

Instantly share code, notes, and snippets.

@kasperkamperman
Created March 9, 2017 09:09
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 kasperkamperman/d56793a995a0496beca4ffe3ec966ed0 to your computer and use it in GitHub Desktop.
Save kasperkamperman/d56793a995a0496beca4ffe3ec966ed0 to your computer and use it in GitHub Desktop.
/*
INPUT_PULLUP doesn't seem to work when using the pin as an interrupt and
also use it to go out of sleep mode.
The pin floats when not attached to ground. That shouldn't happen because of the
internal pull-up. However the sleeping part works well from both states of the button (LOW or "floating").
*/
#include "application.h"
#pragma SPARK_NO_PREPROCESSOR
SYSTEM_THREAD(ENABLED);
SYSTEM_MODE(MANUAL);
void buttonPress();
bool WkpValue;
void setup()
{ WiFi.off();
Serial.begin(57600);
pinMode(WKP, INPUT_PULLUP);
attachInterrupt(WKP, buttonPress, CHANGE);
System.sleep(WKP, CHANGE);
}
void buttonPress() {
WkpValue = digitalRead(WKP);
Serial.print("p: ");
Serial.println(WkpValue);
}
void loop()
{ Serial.println("Awake");
delay(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment