-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRFID.ino
executable file
·135 lines (99 loc) · 2.83 KB
/
RFID.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**
* Clears out the memory space for the tag to 0s.
*/
void clearCode() {
for (int i = 0; i < CODE_LEN; i++) {
tag[i] = 0;
}
}
/**
* Sends the tag to the computer.
*/
void sendCode() {
//This is where I would add a return value (the code) to "validiate" or whatever at.
Serial.print("LINKED TO:");
String temp = "";
char full_tag[10];
for (int i = 0; i < CODE_LEN; i++) {
temp = temp + "" + tag[i];
if (i == 9) //Edits by riley porter
Serial.println(tag[i]); //This checks to see if its the last byte
else //If it is it will print a "new line" so that the codes to jumble together
Serial.print(tag[i]);
}
if (temp.length() == 10) {
Serial.println(temp);
// stringOne = "John Doe";
//stringTwo = "Community Organizer";
//stringThree = "LinkedIn Profile Link";
if (temp == "0415EAD421") {
Serial.println("yadida");
//readerclo();
}
else if (temp == "041580978F") {
Serial.println("this is potus");
}
}
}
/* else if(temp == "0415ED287E"){
for(int i =0; i < ROWS; i++){
for(int j = 0; j < COLS; j++){
setColour(0,255,0);
singlePixel(j,i);
pixels.show();
delay(500);
}
}
}
*/
//Serial.println(temp.length());
/**************************************************************/
/******************** RFID Functions ***********************/
/**************************************************************/
void enableRFID() {
digitalWrite(RFID_ENABLE, LOW);
// digitalWrite(LED, LOW);
}
void disableRFID() {
digitalWrite(RFID_ENABLE, HIGH);
// digitalWrite(LED, HIGH);
}
/**
* Blocking function, waits for and gets the RFID tag.
*/
void getRFIDTag() {
byte next_byte;
while (mySerial.available() <= 0) {}
if ((next_byte = mySerial.read()) == START_BYTE) {
byte bytesread = 0;
while (bytesread < CODE_LEN) {
if (mySerial.available() > 0) { //wait for the next byte
if ((next_byte = mySerial.read()) == STOP_BYTE) break;
tag[bytesread++] = next_byte;
}
}
}
}
/**
* Waits for the next incoming tag to see if it matches
* the current tag.
*/
boolean isCodeValid() {
byte next_byte;
int count = 0;
while (mySerial.available() < 2) { //there is already a STOP_BYTE in buffer
delay(1); //probably not a very pure millisecond
if (count++ > VALIDATE_LENGTH) return false;
}
mySerial.read(); //throw away extra STOP_BYTE
if ((next_byte = mySerial.read()) == START_BYTE) {
byte bytes_read = 0;
while (bytes_read < CODE_LEN) {
if (mySerial.available() > 0) { //wait for the next byte
if ((next_byte = mySerial.read()) == STOP_BYTE) break;
if (tag[bytes_read++] != next_byte) return false;
}
}
}
return true;
}