-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharduino.ino
67 lines (55 loc) · 1.81 KB
/
arduino.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <MemoryFree.h>
#define ENABLE 7 // Set the pin number for enabling the RFID reader. The Audio Shield uses pins 2-5.
int val = 0;
char code[10];
int bytesread = 0;
String filename = "";
String codeString = "";
char *filenameChar;
void setup() {
Serial.begin(2400);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
pinMode(ENABLE, OUTPUT);
digitalWrite(ENABLE, LOW); // activate the RFID reader
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
}
void loop() {
//Serial.print(F("freeMemory()="));
//Serial.println(freeMemory());
delay(1000);
if(Serial.available() > 0) { // if data available from reader
if((val = Serial.read()) == 10) { // check for header
bytesread = 0;
while(bytesread<10) { // read 10 digit code
if( Serial.available() > 0) {
val = Serial.read();
if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading
break; // stop reading
}
code[bytesread] = val; // add the digit
bytesread++; // ready to read next digit
}
}
if(bytesread == 10) { // if 10 digit read is complete
codeString = (String)code;
codeString.trim(); // trims the code to one line (for some reason it was longer)
swipe(codeString);
delay(5000);
digitalWrite(ENABLE, LOW);
Serial.begin(2400);
}
bytesread = 0;
}
}
}
void swipe(String swipeCode) {
Serial.println(swipeCode);
//Serial.print("TAG code is: " + codeString); // possibly a good TAG
Serial.flush();
Serial.end();
digitalWrite(ENABLE, HIGH);
}