update hiển thị led 13 tren Lattepanda
This commit is contained in:
parent
5deb74ce6d
commit
5931745257
|
@ -1,4 +1,4 @@
|
|||
+---------+
|
||||
/* +---------+
|
||||
+----------------------------------->READ TAGS+^------------------------------------------+
|
||||
| +--------------------+ |
|
||||
| | | |
|
||||
|
@ -45,7 +45,7 @@
|
|||
|
||||
// #include <Servo.h>
|
||||
|
||||
#define COMMON_ANODE
|
||||
//#define COMMON_ANODE
|
||||
|
||||
#ifdef COMMON_ANODE
|
||||
#define LED_ON LOW
|
||||
|
@ -55,6 +55,8 @@
|
|||
#define LED_OFF LOW
|
||||
#endif
|
||||
|
||||
#define ledView 13
|
||||
|
||||
#define redLed 3 // Set Led Pins
|
||||
#define greenLed 6
|
||||
#define blueLed 5
|
||||
|
@ -77,9 +79,12 @@ byte masterCard[4]; // Stores master card's ID read from EEPROM
|
|||
#define RST_PIN 9
|
||||
MFRC522 mfrc522(SS_PIN, RST_PIN);
|
||||
|
||||
bool Debug = false;
|
||||
|
||||
///////////////////////////////////////// Setup ///////////////////////////////////
|
||||
void setup() {
|
||||
//Arduino Pin Configuration
|
||||
pinMode(ledView,OUTPUT);
|
||||
pinMode(redLed, OUTPUT);
|
||||
pinMode(greenLed, OUTPUT);
|
||||
pinMode(blueLed, OUTPUT);
|
||||
|
@ -90,24 +95,28 @@ void setup() {
|
|||
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(ledView,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
|
||||
}
|
||||
|
||||
//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
|
||||
// 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"));
|
||||
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"));
|
||||
|
@ -140,8 +149,11 @@ void setup() {
|
|||
// 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) {
|
||||
// Serial.println(F("No Master Card Defined"));
|
||||
// Serial.println(F("Scan A PICC to Define as Master Card"));
|
||||
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
|
||||
|
@ -154,18 +166,30 @@ void setup() {
|
|||
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.
|
||||
// Serial.println(F("Master Card Defined"));
|
||||
if (Debug ==1){
|
||||
Serial.println(F("Master Card Defined"));
|
||||
}
|
||||
|
||||
}
|
||||
// Serial.println(F("-------------------"));
|
||||
// Serial.println(F("Master Card's UID"));
|
||||
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
|
||||
// Serial.print(masterCard[i], HEX);
|
||||
if (Debug ==1){
|
||||
Serial.print(masterCard[i], HEX);
|
||||
}
|
||||
|
||||
}
|
||||
// Serial.println("");
|
||||
// Serial.println(F("-------------------"));
|
||||
// Serial.println(F("Everything is ready"));
|
||||
// Serial.println(F("Waiting PICCs to be scanned"));
|
||||
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);
|
||||
|
@ -185,13 +209,18 @@ void loop () {
|
|||
digitalWrite(greenLed, LED_OFF); // Make sure led is off
|
||||
digitalWrite(blueLed, LED_OFF); // Make sure led is off
|
||||
// Give some feedback
|
||||
// Serial.println(F("Wipe Button Pressed"));
|
||||
// Serial.println(F("Master Card will be Erased! in 10 seconds"));
|
||||
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.
|
||||
// Serial.println(F("Master Card Erased from device"));
|
||||
// Serial.println(F("Please reset to re-program Master Card"));
|
||||
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"));
|
||||
|
@ -266,8 +295,10 @@ void granted ( uint16_t setDelay) {
|
|||
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
|
||||
digitalWrite(relay, HIGH); // Relock door
|
||||
digitalWrite(ledView,HIGH);
|
||||
delay(200); // Hold green LED on for a second
|
||||
}
|
||||
|
||||
|
@ -350,6 +381,7 @@ void normalModeOn () {
|
|||
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 //////////////////////////////
|
||||
|
@ -570,6 +602,7 @@ void CheckButton()
|
|||
else
|
||||
{
|
||||
digitalWrite(relay, HIGH); // Unlock door!
|
||||
digitalWrite(ledView,HIGH);
|
||||
relay_stt = false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user