 }
 
 
-void notify(){
-  if(connected == true){
-    // Read input and store
-    uint8_t value =  0;
-    if(digitalRead(INPUT_PIN) == LOW){
-      value = 1;
-    }
-  
-    // Send 1 byte of data with value
-    pCharacteristic->setValue((uint8_t*)&value, 1);
-    pCharacteristic->notify();
-    Serial.println("Notification sent");
-  }
-  else{
-    Serial.println("Value not sent. Not connected.");
-  }
-}
-
-void IRAM_ATTR onPinChanged(){
+void newValue(){
   pendingValue = true;
+  lastEvent = millis();
 }
 
 
+void IRAM_ATTR onPinChanged(){
+  newValue();
+}
+
 void setup() {
+  setCpuFrequencyMhz(80);
   Serial.begin(115200);
 
   // Set up BLE

bool connected = false;
bool pendingValue = false;


class BLECallback: public BLEServerCallbacks {
    void onConnect(BLEServer* pServer) {
      Serial.println("Connected");
      connected = true;
    };



#define INPUT_PIN 0
#define DEBOUNCE_TIME_MILLIS 50
#define SLEEP_TIME_MILLIS 10000

BLEServer* pServer = NULL;
BLECharacteristic* pCharacteristic = NULL;
