     buzz = SILENT;
 }
 
+void grote_schakelaar_loop() {
+  // debounce
+  static unsigned long lst = 0; 
+
+  if (digitalRead(GROTE_SCHAKELAAR) != last_grote_schakelaar && lst = 0) {
+    last_grote_schakelaar = digitalRead(GROTE_SCHAKELAAR);
+    lst = millis();
+  };
+
+  // Start trusting the value once it has been stable for 100 milli Seconds.
+  //
+  if (lst && millis() - lst > 100) {
+    // stable for over 100 milliseconds; so we trust this value;
+    if (last_grote_schakelaar == GROTE_SCHAKELAAR_OPEN) {
+      Log.println("Grote schakelaar: Space is now open.");
+      node.send(GROTE_SCHAKELAAR_TOPIC, "1");
+    } else {
+      Log.println("Grote schakelaar: Space is now closed.");
+      node.send(GROTE_SCHAKELAAR_TOPIC, "0");
+    };
+  }
+}
+
 void loop() {
   node.loop();
   stepper.run();
   buzzer_loop();
+  grote_schakelaar_loop();
 
   if (laststate != machinestate) {
     Debug.printf("Changed from state <%s> to state <%s>\n",


  reader.onSwipe([](const char * tag) -> ACBase::cmd_result_t {

    // special case of the someone is leaving swipe; technically
    // we sent this as an 'ok to leave' sort of request; so the privacy
    // of the tag/user is preserved on the wire.
    //
    // We expect the door to not be in the opening process; but we do
    // allow a swipe post opening - e.g. when some-one holds the door
    // open als someone comes in.
    //
    if ((machinestate == WAITINGFORCARD || machinestate >= OPEN) && digitalRead(DOOR_SENSOR) == DOOR_IS_OPEN)
    {
      Debug.printf("Detected a leave; sent tag to master.\n");

      node.request_approval(tag, "leave", NULL, false);
      swipeouts_count++;
      buzz = LEAVE;
      return ACBase::CMD_CLAIMED;
    }

    // avoid swithing messing with the door open process
    if (machinestate > CHECKINGCARD) {
      Debug.printf("Ignoring a normal swipe - as we're still in some open process.");
      return ACBase::CMD_CLAIMED;


// See https://mailman.makerspaceleiden.nl/mailman/private/deelnemers/2019-February/019837.html
//
// #define DOOR_SENSOR       (34)
// #define DOOR_IS_OPEN      (LOW)
// #define AARTLED_GPIO      (16) // weggehaald, maart 2019, Lucas

// Introduced by alex - 2020-01-8
#define GROTE_SCHAKELAAR_SENSOR       (34)
#define GROTE_SCHAKELAAR_IS_OPEN     (LOW)
#define GROTE_SCHAKELAAR_TOPIC      "makerspace/groteschakelaar"

int last_grote_schakelaar = 2;

#define BUZZ_TIME (5 * 1000) // Buzz 8 seconds.

