Skip to content

Commit

Permalink
✨ Adds open/cloes button support
Browse files Browse the repository at this point in the history
  • Loading branch information
donatmarko committed Jan 17, 2019
1 parent 9378375 commit 38ecd86
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ lib_deps =
https://github.com/miguelbalboa/rfid#ea7ee3f3daafd46d0c5b8438ba41147c384a1f0d
https://github.com/monkeyboard/Wiegand-Protocol-Library-for-Arduino.git
Time
Bounce2

; boards which GPIO0 and RESET controlled using two NPN transistors as nodemcu devkit (includes wemos d1 mini)
[env:generic]
Expand Down
11 changes: 11 additions & 0 deletions src/config.esp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ bool ICACHE_FLASH_ATTR loadConfiguration()
digitalWrite(wifipin, LEDoff);
}
}

if (hardware.containsKey("buttonpin"))
{
buttonPin = hardware["buttonpin"];
if (buttonPin != 255)
{
button = Bounce();
button.attach(buttonPin, INPUT_PULLUP);
button.interval(30);
}
}
#ifdef OFFICIALBOARD
setupWiegandReader(5, 4);
#endif
Expand Down
15 changes: 14 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ SOFTWARE.
#include <Ticker.h>
#include "Ntp.h"
#include <AsyncMqttClient.h>
#include <Bounce2.h>

//#define DEBUG

Expand All @@ -58,6 +59,7 @@ MFRC522 mfrc522 = MFRC522();
PN532 pn532;
WIEGAND wg;
RFID_Reader RFIDr;
Bounce button;

int rfidss;
int readerType;
Expand Down Expand Up @@ -94,6 +96,7 @@ bool wifiFlag = false;
bool configMode = false;
int wmode;
uint8_t wifipin = 255;
uint8_t buttonPin = 255;
#define LEDoff HIGH
#define LEDon LOW

Expand Down Expand Up @@ -223,6 +226,16 @@ void ICACHE_RAM_ATTR loop()
uptime = NTP.getUptimeSec();
previousLoopMillis = currentMillis;

button.update();
if (button.fell())
{
#ifdef DEBUG
Serial.println("Button has been pressed");
#endif

activateRelay = true;
}

if (wifipin != 255 && configMode && !wmode)
{
if (!wifiFlag)
Expand Down Expand Up @@ -268,7 +281,7 @@ void ICACHE_RAM_ATTR loop()
#endif
digitalWrite(relayPin, !relayType);
}
activateRelay = false;
activateRelay = false;
}
}
else if (lockType == 0) // momentary relay mode
Expand Down

0 comments on commit 38ecd86

Please sign in to comment.