From 65daad87acd1f3e141cc3961ebd9e5a32177f9de Mon Sep 17 00:00:00 2001 From: haimd Date: Thu, 14 Jan 2021 14:58:41 +0700 Subject: [PATCH] Clear --- Lock.rar | Bin 6684 -> 0 bytes Lock/Lock.ino | 600 ++------------------------------------------------ 2 files changed, 16 insertions(+), 584 deletions(-) delete mode 100644 Lock.rar diff --git a/Lock.rar b/Lock.rar deleted file mode 100644 index a9668825d11f9465c6f64876c559a44b2b28e11d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6684 zcmb8!Ra+Dcv<2W98fod4?(RmUq-&^wp}V^qM7p~hsiC`(Mmm&|8oH(PeCPawv!C_s zn{~f#UJVmhDiUNM0C}fN8x4qv3_t<``EO78>8;t;j(_P>v#!?B-V0ZwA zl9QPo$NxTd8%L)P@Nh7>IbrC=GH`NEk602>nukZ)2+z{!-Be_2yC!~@ez{n~@vO!1 z8MRo`lFKGs(}|sjqY93eHbzbfTY=4U;r<({K~{DZz9f7Z?LThz7d$X+h(3LVp|Y}? z&d$F}6;*~%cc4`GBIVp=K+wSHNv)V}iR#k`N1 zT2Vf1@G=_`Fx-fFP@23GHd9-=6Or5gvawE@=3{gHQR946)S&lP9dv#TyjM|BT=3wt zd1$)l(%VS88Xdncys^RL;oJe)4MTkD|3!jT_$w{myPln|{M)s&{d&pRANPl*|M0FW zY|J;D3Bj5FK~2Y!zdpZYU5ig9MpB2JCUV-eNTz;uO8r%fT*{4UetqxPAt2}jS>M>G z(8}`bOcSSEg0cobSL5GoT)9olU4#S0fDab3uvpT-+4`TvESRIf+TG78M4bSevJ|Y5v zMLGJ$WIb*6+JTcp=WEMGXC0x>zo|m|YFYRK&lVeyzux=!8p~%VNjwN;hWN%37|P)k;RTj!U~s zARhqs(A6R(^A5iVuQvjcmA9LZ|Rb z!)Q6PR`oD0^!{TBp4#_Q83is#xb~`b*T&n77|!T2T~j>2DX(eyl+K^%&F_)hb;`uA ztl(NJL~n|hx#86fqtY)12;x!^&qD{w14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)*XnysGTX5Pi36889m3cXP)#NljBiDE}p+!_O2R5hhA$xCB zH5tc5k^aIkN7&cuabfRkGcZiSWOpCybe>Vnx3yTX4gg6BFgWuYz>lNAfP6 zEbl^f06k{c^XWCpz?gEYOnwvE4Jvo`Xe53mkm;vedB)N`$?XG6f&}sdn8xYXl$RPu z`m-N=+;ypQ1@AYXnW`9katrgtDQt8!nIA#oG2kE37*#J!c#4WOq7in4w3mJPYc2PV6WR`HD+4a-PJkM*dusW%jJ=K;BUYTyzmEu-WTHJrke zJ&|ZCDe`9;4$pA=yDZ1>K-5WsC~o*r+p^t%&g|nwg%itB=U^4KQMGz^xv_TxpOnuD zFMe|k^?fj(wn3|$`;eE-u}%?+1nAhexxtoio))1p9Z?POIY~abD(tyE?f>2Zvv*$_EU`|d_z3rv9ByfE%h{$ zRIoyx5dltYqAa=U9x*cv_QX0?K>MvZe&D8Ytx{zs7MmL8^QN+68RZH752i7dJ!0Hj-QCsAWd60uktKY%KkO=LgKOKpdd-! z#?Qjm+YbMD@$fK|Og9L7{?B~=NON*1GXH3f#dn}i)Y*zF+0ns%8*NQuQ%_L*hcN&|05;&i3kCoX{?}ms^A~E=`Tz5m2n5Y0On9UY h0N}s;*Tbo+g0T#wcmef1oc~|TA@|Z&het#J{12@`!{z`0 diff --git a/Lock/Lock.ino b/Lock/Lock.ino index 96ebc3e..8e646f4 100644 --- a/Lock/Lock.ino +++ b/Lock/Lock.ino @@ -38,34 +38,10 @@ #include // RC522 Module uses SPI protocol #include // Library for Mifare RC522 Devices #include -/* - Instead of a Relay you may want to use a servo. Servos can lock and unlock door locks too - Relay will be used by default -*/ -// #include - -//#define COMMON_ANODE -// Ver 1 -//#ifdef COMMON_ANODE -//#define LED_ON LOW -//#define LED_OFF HIGH -//#else -//#define LED_ON HIGH -//#define LED_OFF LOW -//#endif -// -//#define Light 7 #define ledView 13 -// -//#define redLed 3 // Set Led Pins -//#define greenLed 6 -//#define blueLed 5 -// -//#define relay A2 //8 // Set Relay Pin -//#define wipeB 2 // Button pin for WipeMode -//#define button 7 // button exit -// -------------------------------------------- + + //Ver 3 // LED 12V - A1 //Relay 1 - D5 @@ -96,173 +72,44 @@ #define Light A1 // Led tro sang camera +int stt; +int stt_old; +String input; +int stt_2; +int stt_old_2; +String input_2; + bool Light_stt = false; bool relay_stt = false; bool relay_stt_2 = false; bool sttRun = false; -bool programMode = false; // initialize programming mode to false - -uint8_t successRead; // Variable integer to keep if we have Successful Read from Reader - -byte storedCard[4]; // Stores an ID read from EEPROM -byte readCard[4]; // Stores scanned ID read from RFID Module -byte masterCard[4]; // Stores master card's ID read from EEPROM - -// Create MFRC522 instance. -#define SS_PIN 10 -#define RST_PIN 9 -MFRC522 mfrc522(SS_PIN, RST_PIN); - bool Debug = false; ///////////////////////////////////////// Setup /////////////////////////////////// void setup() { + //Arduino Pin Configuration pinMode(13, OUTPUT); pinMode(Light, OUTPUT); digitalWrite(13, LOW); - //Arduino Pin Configuration + pinMode(ledView, OUTPUT); - pinMode(redLed, OUTPUT); - pinMode(greenLed, OUTPUT); - pinMode(blueLed, OUTPUT); pinMode(wipeB, INPUT_PULLUP); // Enable pin's pull up resistor pinMode(relay, OUTPUT); pinMode(relay_2, OUTPUT); pinMode(button,INPUT); pinMode(button_2,INPUT); - //Be careful how relay circuit behave on while resetting or power-cycling your Arduino + digitalWrite(relay, HIGH); // Make sure door is locked digitalWrite(relay_2, HIGH); // Make sure door is locked -// delay(2000); -// digitalWrite(relay, LOW); -// delay(2000); -// digitalWrite(relay_2, HIGH); // Make sure door is locked -// delay(2000); -// digitalWrite(redLed, LED_OFF); // Make sure led is off -// digitalWrite(greenLed, LED_OFF); // Make sure led is off -// digitalWrite(blueLed, LED_OFF); // Make sure led is off digitalWrite(Light, LOW); - //Protocol Configuration Serial.begin(9600); // Initialize serial communications with PC - -// -// SPI.begin(); // MFRC522 Hardware uses SPI protocol -// mfrc522.PCD_Init(); // Initialize MFRC522 Hardware -// if (Debug == true) -// { -// //If you set Antenna Gain to Max it will increase reading distance -// mfrc522.PCD_SetAntennaGain(mfrc522.RxGain_max); -// Serial.println(F("Access Control Example v0.1")); // For debugging purposes -// } -// -// ShowReaderDetails(); // Show details of PCD - MFRC522 Card Reader details -// -// //Wipe Code - If the Button (wipeB) Pressed while setup run (powered on) it wipes EEPROM -// if (digitalRead(wipeB) == LOW) -// { // when button pressed pin should get low, button connected to ground -// digitalWrite(redLed, LED_ON); // Red Led stays on to inform user we are going to wipe -// if (Debug == 1) -// { -// Serial.println(F("Wipe Button Pressed")); -// Serial.println(F("You have 10 seconds to Cancel")); -// Serial.println(F("This will be remove all records and cannot be undone")); -// } -// bool buttonState = monitorWipeButton(10000); // Give user enough time to cancel operation -// if (buttonState == true && digitalRead(wipeB) == LOW) -// { // If button still be pressed, wipe EEPROM -// // Serial.println(F("Starting Wiping EEPROM")); -// for (uint16_t x = 0; x < EEPROM.length(); x = x + 1) -// { //Loop end of EEPROM address -// if (EEPROM.read(x) == 0) -// { //If EEPROM address 0 -// // do nothing, already clear, go to the next address in order to save time and reduce writes to EEPROM -// } -// else -// { -// EEPROM.write(x, 0); // if not write 0 to clear, it takes 3.3mS -// } -// } -// // Serial.println(F("EEPROM Successfully Wiped")); -// digitalWrite(redLed, LED_OFF); // visualize a successful wipe -// delay(200); -// digitalWrite(redLed, LED_ON); -// delay(200); -// digitalWrite(redLed, LED_OFF); -// delay(200); -// digitalWrite(redLed, LED_ON); -// delay(200); -// digitalWrite(redLed, LED_OFF); -// } -// else -// { -// // Serial.println(F("Wiping Cancelled")); // Show some feedback that the wipe button did not pressed for 15 seconds -// digitalWrite(redLed, LED_OFF); -// } -// } -// // Check if master card defined, if not let user choose a master card -// // This also useful to just redefine the Master Card -// // You can keep other EEPROM records just write other than 143 to EEPROM address 1 -// // EEPROM address 1 should hold magical number which is '143' -// if (EEPROM.read(1) != 143) -// { -// if (Debug == 1) -// { -// Serial.println(F("No Master Card Defined")); -// Serial.println(F("Scan A PICC to Define as Master Card")); -// } -// -// do -// { -// successRead = getID(); // sets successRead to 1 when we get read from reader otherwise 0 -// digitalWrite(blueLed, LED_ON); // Visualize Master Card need to be defined -// delay(200); -// digitalWrite(blueLed, LED_OFF); -// delay(200); -// } while (!successRead); // Program will not go further while you not get a successful read -// for (uint8_t j = 0; j < 4; j++) -// { // Loop 4 times -// EEPROM.write(2 + j, readCard[j]); // Write scanned PICC's UID to EEPROM, start from address 3 -// } -// EEPROM.write(1, 143); // Write to EEPROM we defined Master Card. -// if (Debug == 1) -// { -// Serial.println(F("Master Card Defined")); -// } -// } -// if (Debug == 1) -// { -// Serial.println(F("-------------------")); -// Serial.println(F("Master Card's UID")); -// } -// -// for (uint8_t i = 0; i < 4; i++) -// { // Read Master Card's UID from EEPROM -// masterCard[i] = EEPROM.read(2 + i); // Write it to masterCard -// if (Debug == 1) -// { -// Serial.print(masterCard[i], HEX); -// } -// } -// if (Debug == 1) -// { -// Serial.println(""); -// Serial.println(F("-------------------")); -// Serial.println(F("Everything is ready")); -// Serial.println(F("Waiting PICCs to be scanned")); -// } -// -// cycleLeds(); // Everything ready lets give user some feedback by cycling leds -// // } -// // wdt_enable(WDTO_500MS); - } -//void SerialRead(); -//void ReadButton(); + ///////////////////////////////////////// Main Loop /////////////////////////////////// void loop() { @@ -270,118 +117,6 @@ void loop() SerialRead(); CheckButton(); } -// do -// { -// ReadButton(); -// SerialRead(); -// -// successRead = getID(); // sets successRead to 1 when we get read from reader otherwise 0 -// // When device is in use if wipe button pressed for 10 seconds initialize Master Card wiping -// if (digitalRead(wipeB) == LOW) -// { // Check if button is pressed -// // Visualize normal operation is iterrupted by pressing wipe button Red is like more Warning to user -// digitalWrite(redLed, LED_ON); // Make sure led is off -// digitalWrite(greenLed, LED_OFF); // Make sure led is off -// digitalWrite(blueLed, LED_OFF); // Make sure led is off -// // Give some feedback -// if (Debug == 1) -// { -// Serial.println(F("Wipe Button Pressed")); -// Serial.println(F("Master Card will be Erased! in 10 seconds")); -// } -// -// bool buttonState = monitorWipeButton(10000); // Give user enough time to cancel operation -// if (buttonState == true && digitalRead(wipeB) == LOW) -// { // If button still be pressed, wipe EEPROM -// EEPROM.write(1, 0); // Reset Magic Number. -// if (Debug == 1) -// { -// Serial.println(F("Master Card Erased from device")); -// Serial.println(F("Please reset to re-program Master Card")); -// } -// while (1) -// ; -// } -// // Serial.println(F("Master Card Erase Cancelled")); -// } -// if (programMode) -// { -// cycleLeds(); // Program Mode cycles through Red Green Blue waiting to read a new card -// } -// else -// { -// normalModeOn(); // Normal mode, blue Power LED is on, all others are off -// } -// CheckButton(); -// } while (!successRead); //the program will not go further while you are not getting a successful read -// -// if (programMode) -// { -// if (isMaster(readCard)) -// { //When in program mode check First If master card scanned again to exit program mode -// // Serial.println(F("Master Card Scanned")); -// // Serial.println(F("Exiting Program Mode")); -// // Serial.println(F("-----------------------------")); -// programMode = false; -// return; -// } -// else -// { -// if (findID(readCard)) -// { // If scanned card is known delete it -// // Serial.println(F("I know this PICC, removing...")); -// deleteID(readCard); -// // Serial.println("-----------------------------"); -// // Serial.println(F("Scan a PICC to ADD or REMOVE to EEPROM")); -// } -// else -// { // If scanned card is not known add it -// // Serial.println(F("I do not know this PICC, adding...")); -// writeID(readCard); -// // Serial.println(F("-----------------------------")); -// // Serial.println(F("Scan a PICC to ADD or REMOVE to EEPROM")); -// } -// } -// } -// else -// { -// if (isMaster(readCard)) -// { // If scanned card's ID matches Master Card's ID - enter program mode -// programMode = true; -// // Serial.println(F("Hello Master - Entered Program Mode")); -// uint8_t count = EEPROM.read(0); // Read the first Byte of EEPROM that -// // Serial.print(F("I have ")); // stores the number of ID's in EEPROM -// // Serial.print(count); -// // Serial.print(F(" record(s) on EEPROM")); -// // Serial.println(""); -// // Serial.println(F("Scan a PICC to ADD or REMOVE to EEPROM")); -// // Serial.println(F("Scan Master Card again to Exit Program Mode")); -// // Serial.println(F("-----------------------------")); -// } -// else -// { -// if (findID(readCard)) -// { // If not, see if the card is in the EEPROM -// // Serial.println(F("Welcome, You shall pass")); -// relay_stt = true; -// granted(4000); // Open the door lock for 300 ms -// ClearSerialdata(); -// } -// else -// { // If not, show that the ID was not valid -// // Serial.println(F("You shall not pass")); -// denied(); -// } -// } -// } -// -//} - - - -//---------------------------------------- -// wdt_reset(); -//} ///////////////////////////////////////// Access Granted /////////////////////////////////// // Turn on Light camera @@ -396,9 +131,7 @@ void TurnOff_Light() { void granted(uint16_t setDelay) { - digitalWrite(blueLed, LED_OFF); // Turn off blue LED - digitalWrite(redLed, LED_OFF); // Turn off red LED - digitalWrite(greenLed, LED_ON); // Turn on green LED + digitalWrite(relay, LOW); // Unlock door! digitalWrite(ledView, LOW); delay(setDelay); // Hold door lock open for given seconds @@ -409,323 +142,22 @@ void granted(uint16_t setDelay) void granted_2(uint16_t setDelay) { - digitalWrite(blueLed, LED_OFF); // Turn off blue LED - digitalWrite(redLed, LED_OFF); // Turn off red LED - digitalWrite(greenLed, LED_ON); // Turn on green LED + digitalWrite(relay_2, LOW); // Unlock door! digitalWrite(ledView, LOW); -// digitalWrite(Light, HIGH); delay(setDelay); // Hold door lock open for given seconds digitalWrite(relay_2, HIGH); // Relock door digitalWrite(ledView, HIGH); -// digitalWrite(Light, LOW); delay(200); // Hold green LED on for a second } -///////////////////////////////////////// Access Denied /////////////////////////////////// -void denied() -{ - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - digitalWrite(redLed, LED_ON); // Turn on red LED - delay(1000); -} - -///////////////////////////////////////// Get PICC's UID /////////////////////////////////// -uint8_t getID() -{ - // Getting ready for Reading PICCs - if (!mfrc522.PICC_IsNewCardPresent()) - { //If a new PICC placed to RFID reader continue - return 0; - } - if (!mfrc522.PICC_ReadCardSerial()) - { //Since a PICC placed get Serial and continue - return 0; - } - // There are Mifare PICCs which have 4 byte or 7 byte UID care if you use 7 byte PICC - // I think we should assume every PICC as they have 4 byte UID - // Until we support 7 byte PICCs - // Serial.println(F("Scanned PICC's UID:")); - for (uint8_t i = 0; i < 4; i++) - { // - readCard[i] = mfrc522.uid.uidByte[i]; - // Serial.print(readCard[i], HEX); - } - // Serial.println(""); - mfrc522.PICC_HaltA(); // Stop reading - return 1; -} -int k; -void ShowReaderDetails() -{ - // Get the MFRC522 software version - byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg); - // Serial.print(F("MFRC522 Software Version: 0x")); - // Serial.print(v, HEX); - if (v == 0x91) - // Serial.print(F(" = v1.0")); - k = 0; - else if (v == 0x92) - // Serial.print(F(" = v2.0")); - k = 1; - else - // Serial.print(F(" (unknown),probably a chinese clone?")); - // Serial.println(""); - // When 0x00 or 0xFF is returned, communication probably failed - if ((v == 0x00) || (v == 0xFF)) - { - // Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?")); - // Serial.println(F("SYSTEM HALTED: Check connections.")); - // Visualize system is halted - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - digitalWrite(redLed, LED_ON); // Turn on red LED - while (true) - ; // do not go further - } -} - -///////////////////////////////////////// Cycle Leds (Program Mode) /////////////////////////////////// -void cycleLeds() -{ - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - digitalWrite(greenLed, LED_ON); // Make sure green LED is on - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - delay(200); - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - digitalWrite(blueLed, LED_ON); // Make sure blue LED is on - delay(200); - digitalWrite(redLed, LED_ON); // Make sure red LED is on - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - delay(200); -} - -//////////////////////////////////////// Normal Mode Led /////////////////////////////////// -void normalModeOn() -{ - digitalWrite(blueLed, LED_ON); // Blue LED ON and ready to read card - digitalWrite(redLed, LED_OFF); // Make sure Red LED is off - digitalWrite(greenLed, LED_OFF); // Make sure Green LED is off - digitalWrite(relay, HIGH); // Make sure Door is Locked - digitalWrite(ledView, HIGH); -} - -//////////////////////////////////////// Read an ID from EEPROM ////////////////////////////// -void readID(uint8_t number) -{ - uint8_t start = (number * 4) + 2; // Figure out starting position - for (uint8_t i = 0; i < 4; i++) - { // Loop 4 times to get the 4 Bytes - storedCard[i] = EEPROM.read(start + i); // Assign values read from EEPROM to array - } -} - -///////////////////////////////////////// Add ID to EEPROM /////////////////////////////////// -void writeID(byte a[]) -{ - if (!findID(a)) - { // Before we write to the EEPROM, check to see if we have seen this card before! - uint8_t num = EEPROM.read(0); // Get the numer of used spaces, position 0 stores the number of ID cards - uint8_t start = (num * 4) + 6; // Figure out where the next slot starts - num++; // Increment the counter by one - EEPROM.write(0, num); // Write the new count to the counter - for (uint8_t j = 0; j < 4; j++) - { // Loop 4 times - EEPROM.write(start + j, a[j]); // Write the array values to EEPROM in the right position - } - successWrite(); - // Serial.println(F("Succesfully added ID record to EEPROM")); - } - else - { - failedWrite(); - // Serial.println(F("Failed! There is something wrong with ID or bad EEPROM")); - } -} - -///////////////////////////////////////// Remove ID from EEPROM /////////////////////////////////// -void deleteID(byte a[]) -{ - if (!findID(a)) - { // Before we delete from the EEPROM, check to see if we have this card! - failedWrite(); // If not - // Serial.println(F("Failed! There is something wrong with ID or bad EEPROM")); - } - else - { - uint8_t num = EEPROM.read(0); // Get the numer of used spaces, position 0 stores the number of ID cards - uint8_t slot; // Figure out the slot number of the card - uint8_t start; // = ( num * 4 ) + 6; // Figure out where the next slot starts - uint8_t looping; // The number of times the loop repeats - uint8_t j; - uint8_t count = EEPROM.read(0); // Read the first Byte of EEPROM that stores number of cards - slot = findIDSLOT(a); // Figure out the slot number of the card to delete - start = (slot * 4) + 2; - looping = ((num - slot) * 4); - num--; // Decrement the counter by one - EEPROM.write(0, num); // Write the new count to the counter - for (j = 0; j < looping; j++) - { // Loop the card shift times - EEPROM.write(start + j, EEPROM.read(start + 4 + j)); // Shift the array values to 4 places earlier in the EEPROM - } - for (uint8_t k = 0; k < 4; k++) - { // Shifting loop - EEPROM.write(start + j + k, 0); - } - successDelete(); - // Serial.println(F("Succesfully removed ID record from EEPROM")); - } -} - -///////////////////////////////////////// Check Bytes /////////////////////////////////// -bool checkTwo(byte a[], byte b[]) -{ - for (uint8_t k = 0; k < 4; k++) - { // Loop 4 times - if (a[k] != b[k]) - { // IF a != b then false, because: one fails, all fail - return false; - } - } - return true; -} - -///////////////////////////////////////// Find Slot /////////////////////////////////// -uint8_t findIDSLOT(byte find[]) -{ - uint8_t count = EEPROM.read(0); // Read the first Byte of EEPROM that - for (uint8_t i = 1; i <= count; i++) - { // Loop once for each EEPROM entry - readID(i); // Read an ID from EEPROM, it is stored in storedCard[4] - if (checkTwo(find, storedCard)) - { // Check to see if the storedCard read from EEPROM - // is the same as the find[] ID card passed - return i; // The slot number of the card - } - } -} - -///////////////////////////////////////// Find ID From EEPROM /////////////////////////////////// -bool findID(byte find[]) -{ - uint8_t count = EEPROM.read(0); // Read the first Byte of EEPROM that - for (uint8_t i = 1; i < count; i++) - { // Loop once for each EEPROM entry - readID(i); // Read an ID from EEPROM, it is stored in storedCard[4] - if (checkTwo(find, storedCard)) - { // Check to see if the storedCard read from EEPROM - return true; - } - else - { // If not, return false - } - } - return false; -} - -///////////////////////////////////////// Write Success to EEPROM /////////////////////////////////// -// Flashes the green LED 3 times to indicate a successful write to EEPROM -void successWrite() -{ - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - digitalWrite(greenLed, LED_OFF); // Make sure green LED is on - delay(200); - digitalWrite(greenLed, LED_ON); // Make sure green LED is on - delay(200); - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - delay(200); - digitalWrite(greenLed, LED_ON); // Make sure green LED is on - delay(200); - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - delay(200); - digitalWrite(greenLed, LED_ON); // Make sure green LED is on - delay(200); -} - -///////////////////////////////////////// Write Failed to EEPROM /////////////////////////////////// -// Flashes the red LED 3 times to indicate a failed write to EEPROM -void failedWrite() -{ - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - delay(200); - digitalWrite(redLed, LED_ON); // Make sure red LED is on - delay(200); - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - delay(200); - digitalWrite(redLed, LED_ON); // Make sure red LED is on - delay(200); - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - delay(200); - digitalWrite(redLed, LED_ON); // Make sure red LED is on - delay(200); -} - -///////////////////////////////////////// Success Remove UID From EEPROM /////////////////////////////////// -// Flashes the blue LED 3 times to indicate a success delete to EEPROM -void successDelete() -{ - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - delay(200); - digitalWrite(blueLed, LED_ON); // Make sure blue LED is on - delay(200); - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - delay(200); - digitalWrite(blueLed, LED_ON); // Make sure blue LED is on - delay(200); - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - delay(200); - digitalWrite(blueLed, LED_ON); // Make sure blue LED is on - delay(200); -} - -////////////////////// Check readCard IF is masterCard /////////////////////////////////// -// Check to see if the ID passed is the master programing card -bool isMaster(byte test[]) -{ - return checkTwo(test, masterCard); -} - -bool monitorWipeButton(uint32_t interval) -{ - uint32_t now = (uint32_t)millis(); - while ((uint32_t)millis() - now < interval) - { - // check on every half a second - if (((uint32_t)millis() % 500) == 0) - { - if (digitalRead(wipeB) != LOW) - return false; - } - } - return true; -} // ADD Code -int stt; -int stt_old; -String input; - - -int stt_2; -int stt_old_2; -String input_2; - - void ReadButton() { stt = digitalRead(button); stt_2 = digitalRead(button_2); -// Serial.print(stt); -// Serial.print("\t"); -// Serial.println(stt_2); + if (stt == 0 && stt_old == 1) { relay_stt = true;