-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lesson 11_RFID.c
118 lines (94 loc) · 4.08 KB
/
Lesson 11_RFID.c
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
/*
RFID Read.c
Reads and displays RFID tag numbers.
Connect: Vcc to 5V, /ENABLE to P2, SOUT to (R = 2.2 k) to P1, GND to GND
http://www.parallax.com/product/28140
16001A00DC (white circle)
010DBEA632 (black circle)
07000CDB16 (key chain)
1E009BC215
1E009D9881
*/
#include "simpletools.h" // Include simpletools
#include "rfidser.h" // Include rfidser
int rfidEn = 2; // Reader /ENABLE pin to P2
int rfidSout = 1; // Reader SOUT pin to P1
rfidser *rfid; // Set up device ID
int main() // Main function
{
rfid = rfid_open(rfidSout, rfidEn); // Open reader, start reading
while(1) // Main loop
{
char *str = rfid_get(rfid, 1000); // Wait up to 1 s for card
print("id = %s.\n", str); // Print ID.
}
}
/*
RFID Read and Compare.c
After scanning your ID tags, you can copy their ID strings over the ones
in the else if statements in this program to recognize them.
Connect: Vcc to 5V, /ENABLE to P2, SOUT to (R = 2.2 k) to P1, GND to GND
http://www.parallax.com/product/28140
*/
#include "simpletools.h" // Include simpletools
#include "rfidser.h" // Include rfidser
int rfidEn = 2; // Reader /ENABLE pin
int rfidSout = 1; // Reader SOUT pin
rfidser *rfid; // Set up device ID
int main() // Main function
{
rfid = rfid_open(rfidSout, rfidEn); // Open reader, start reading
while(1) // Main loop
{
char *str = rfid_get(rfid, 1000); // Wait up to 1 s for card
if(!strcmp(str, "timed out")) // Timed out?
print("No ID scanned.\n"); // display "No ID..."
else if(!strcmp(str, "1E009BC215")) // Tag A ID match?
print("Tag A detected.\n"); // display "Tag A..."
else if(!strcmp(str, "1E009D9881")) // Tag B ID match?
print("Tag B detected.\n"); // display "Tag B..."
else if(!strcmp(str, "16001A00DC")) // Tag B ID match?
print("Tag C detected.\n");
else if(!strcmp(str, "010DBEA632")) // Tag B ID match?
print("Tag D detected.\n");
else // No matches?
print("Unknown ID = %s.\n", str); // print ID.
}
}
//RFID
#include "simpletools.h" // Include simpletools
#include "rfidser.h" // Include rfidser
#include "abdrive.h"
int rfidEn = 2; // Reader /ENABLE pin
int rfidSout = 1; // Reader SOUT pin
rfidser *rfid; // Set up device ID
int main() // Main function
{
rfid = rfid_open(rfidSout, rfidEn); // Open reader, start reading
while(1) // Main loop
{
char *str = rfid_get(rfid, 1000); // Wait up to 1 s for card
if(!strcmp(str, "timed out")) { // Timed out?
print("No ID scanned.\n"); // display "No ID..."
drive_speed(0,0);
}
else if(!strcmp(str, "1E009BC215")) { // Tag A ID match?
print("Tag A detected.\n"); // display "Tag A..."
drive_speed(64,64);
}
else if(!strcmp(str, "1E009D9881")){ // Tag B ID match?
print("Tag B detected.\n"); // display "Tag B..."
drive_speed(-64,-64);
}
else if(!strcmp(str, "16001A00DC")) {
print("Tag C detected.\n");
drive_speed(-32,32);
}
else if(!strcmp(str, "010DBEA632")){
print("Tag D detected.\n");
drive_speed(32,-32);
}
else // No matches?
print("Unknown ID = %s.\n", str); // print ID.
}
}