Академический Документы
Профессиональный Документы
Культура Документы
#include <Wire.h>
#include <RTClib.h>
#include <stdio.h>
#include <constants.h>
#include <vfd.h>
#include <vfd.c>
#include <SPI.h>
#include <SD.h>
#include <Adafruit_PN532.h>
File myFile;
RTC_DS1307 rtc;
int wgnd = 18; // RTC Breakout board doesn't require much juice. Repurposing pin 18 &
19 as GND & +5V output.
int w5v = 19;
{
"4D398796", // Tag 1
"8B2A6474", // Tag 2
"9BF36174", // Tag 3
"0B426B74", // Tag 4
"3BF46B74" // Tag 5
};
Adafruit_PN532 nfc(2, 3); // IRQ, RESET pins : Reset pin not connected by default on the NFC
Shield
/*******************************************************************************/
void setup(void)
{
pinMode(ledPin, OUTPUT);
pinMode(ledPin1, OUTPUT);
VFD_ResetDevice();
ARDUINO_delay(2); // Delay to allow the VFD device to reset clean
delay(10);
VFD_WriteInstruction(CLEAR_LCD);
delay(1000);
VFD_WriteInstruction(SETLINE0);
VFD_WriteString(" SupaLec");
delay(1000);
VFD_WriteInstruction(SETLINE1);
VFD_WriteString(" SupaClokka Mk1");
delay(1000);
pinMode(wgnd, OUTPUT); // this sets pin as GND output for RTC Breakout board
digitalWrite(wgnd, LOW);
pinMode(w5v, OUTPUT); // this sets pin as +5V output for RTC Breakout board
digitalWrite(w5v, HIGH);
Serial.println(F("Initializing RTC..."));
#ifdef AVR
Wire.begin();
#else
Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino Due
#endif
rtc.begin();
/*
if (! rtc.isrunning())
{
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
//rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
rtc.adjust(DateTime(2016, 22, 1, 23, 24, 0));
}
*/
if (!rtc.isrunning())
{
VFD_WriteInstruction(CLEAR_LCD);
delay(100);
VFD_WriteInstruction(SETLINE0);
VFD_WriteString(" RTC failure!");
VFD_WriteInstruction(SETLINE1);
VFD_WriteString(" Call Technician!");
Serial.println(F("Initializing SD card..."));
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
pinMode(SS, OUTPUT);
if (!SD.begin(chipSelect))
{
VFD_WriteInstruction(CLEAR_LCD);
delay(100);
VFD_WriteInstruction(SETLINE0);
VFD_WriteString(" SD Card failure!");
VFD_WriteInstruction(SETLINE1);
VFD_WriteString(" Call Technician!");
myFile = SD.open("myFile.txt"); //Read the Tag information (myFile.txt) to check tag data on SD
card
if (myFile)
{
Serial.println("myFile.txt");
while(myFile.available())
{
Serial.write(myFile.read());
}
}
else
{
Serial.println(F("Error opening myFile.txt."));
return;
}
nfc.begin();
VFD_WriteInstruction(CLEAR_LCD);
delay(100);
VFD_WriteInstruction(SETLINE0);
VFD_WriteString("Swipe your student card...");
Serial.println("Swipe your student card...");
//delay(100);
}
/*******************************************************************************/
void loop()
{
digitalWrite(ledPin, HIGH); // The GREEN LED comes on ready for card swipe
if (scanCode())
digitalWrite(ledPin, LOW); // turn the GREEN LED off (LOW is the voltage level)
digitalWrite(ledPin1, HIGH); // turn the RED LED on (HIGH is the voltage level)
VFD_WriteInstruction(SETLINE1);
VFD_WriteString("Checking, please wait...");
Serial.println("Checking, please wait...");
Serial.println("");
delay (2000);
{
checkCode();
}
delay(2000);
}
/*******************************************************************************/
boolean scanCode()
{
boolean success;
byte uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
byte uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
if (success)
{
//digitalWrite(ledPin, LOW); // turn the GREEN LED off (LOW is the voltage level)
//digitalWrite(ledPin1, HIGH); // turn the RED LED on (HIGH is the voltage level)
VFD_WriteInstruction(CLEAR_LCD);
delay(100);
VFD_WriteInstruction(SETLINE0);
VFD_WriteString("Student number: ");
Serial.print("Student number: ");
Serial.println("");
}
return success;
}
/*******************************************************************************/
void checkCode()
{
boolean codeValid = false;
for (int i = 0; i < numCodes; i++)
{
if (strcmp(code, codes[i]) == 0)
{
codeValid = true;
}
}
if (codeValid)
{
VFD_WriteInstruction(CLEAR_LCD);
delay(100);
VFD_WriteInstruction(SETLINE0);
VFD_WriteString("Welcome, please enter.");
Serial.println("Welcome, please enter.");
Serial.println("");
Serial.println("-----------------------------");
delay(1000);
VFD_WriteInstruction(CLEAR_LCD);
delay(100);
digitalWrite(ledPin, HIGH); // turn the GREEN LED on by making the voltage HIGH
digitalWrite(ledPin1, LOW); // turn the RED LED off by making the voltage LOW
VFD_WriteInstruction(SETLINE0);
VFD_WriteString("Swipe your student card...");
Serial.println("Swipe your student card...");
Serial.println("");
}
else
{
VFD_WriteInstruction(CLEAR_LCD);
delay(100);
VFD_WriteInstruction(SETLINE0);
VFD_WriteString("Unauthorised student card, please inform Reception..");
Serial.println("Unauthorised student card, please inform Reception...");
Serial.println("");
Serial.println("-----------------------------");
delay(1000);
VFD_WriteInstruction(CLEAR_LCD);
delay(100);
digitalWrite(ledPin, HIGH); // turn the GREEN LED on by making the voltage HIGH
digitalWrite(ledPin1, LOW); // turn the RED LED off by making the voltage LOW
VFD_WriteInstruction(SETLINE0);
VFD_WriteString("Swipe your student card...");
Serial.println("Swipe your student card...");
Serial.println("");
//delay(refresh_rate);
}
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
void ARDUINO_DisableInterrupts()
{
noInterrupts();
}
/*****************************************************************************/
void ARDUINO_EnableInterrupts()
{
interrupts();
}
/*****************************************************************************/
/* bzero() is an old familiar friend. It clears an area of memory so that it's contents
can be guaranteed to be free of all corrupting data. We take two parameters, the address
of the area to be cleared and a char length parameter indicating the size in characters
of the area to be cleared.
*/
/*********************************************************************************
**********/
/* bcopy() is another old friend. Here, we copy one area of memory to another. Nice 'n' slick...
*/
void bcopy(unsigned char *SourceAddress, unsigned char *DestinationAddress, unsigned int Length)
{
while (--Length > 0)
*DestinationAddress++ = *SourceAddress++;
}
/*********************************************************************************
**********/