-
Notifications
You must be signed in to change notification settings - Fork 0
/
rfid_cart_with_button.ino
156 lines (133 loc) · 3.81 KB
/
rfid_cart_with_button.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// Connect Vcc and Ground, SDA to A4, SCL to A5 on Arduino
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
#include <AddicoreRFID.h>
#include <SPI.h>
#define uchar unsigned char
#define uint unsigned int
uchar serNumA[5];
uchar fifobytes;
uchar fifoValue;
AddicoreRFID myRFID;
const int chipSelectPin = 100;
const int NRSTPD = 9; // RST Pin
#define MAX_LEN 30
int a,b,d,c=0;
int ledPin = 13;
int inPin = A0;
int val = 0;
void setup()
{
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inPin, INPUT); // declare pushbutton as input
Serial.begin(9600);
SPI.begin();
pinMode(chipSelectPin,OUTPUT);
digitalWrite(chipSelectPin, LOW);
pinMode(NRSTPD,OUTPUT);
digitalWrite(NRSTPD, HIGH);
myRFID.AddicoreRFID_Init();
lcd.begin(16,2);
int a,b,d,c=0;
for(int i = 0; i< 3; i++)
{
lcd.backlight();
delay(500);
lcd.setCursor(3,0);
lcd.print ("welcome");
lcd.setCursor(2,1);
lcd.print ("add products");
lcd.noBacklight();
delay(500);
lcd.backlight();
}
delay (500);
lcd.clear ();
lcd.setCursor(2,0);
lcd.print ("Scan Card");
}
void loop()
{
uchar i, tmp, checksum1;
uchar status;
uchar str[MAX_LEN];
uchar RC_size;
uchar blockAddr;
String mynum = "";
str[1] = 0x4400;
//Find tags, return tag type
status = myRFID.AddicoreRFID_Request(PICC_REQIDL, str);
if (status == MI_OK)
{
Serial.println("RFID tag detected");
Serial.print(str[0],BIN);
Serial.print(" , ");
Serial.print(str[1],BIN);
Serial.println(" ");
}
status = myRFID.AddicoreRFID_Anticoll(str);
if (status == MI_OK)
{
checksum1 = str[0] ^ str[1] ^ str[2] ^ str[3];
Serial.println("The tag's number is : ");
//Serial.print(2);
Serial.print(str[0]);
Serial.print(" , ");
Serial.print(str[1],BIN);
Serial.print(" , ");
Serial.print(str[2],BIN);
Serial.print(" , ");
Serial.print(str[3],BIN);
Serial.print(" , ");
Serial.print(str[4],BIN);
Serial.print(" , ");
Serial.println(checksum1,BIN);
// Should really check all pairs, but for now we'll just use the first
if(str[0] ==203
)
{
lcd.clear ();
a=10;
lcd.setCursor(0,0);
lcd.print("tea");
delay (500);
lcd.setCursor(0,1);
lcd.print ("10");
}
if(str[0] ==75
) {
lcd.clear ();
lcd.setCursor(0,0);
lcd.print("sugger");
delay (500);
lcd.setCursor(0,1);
lcd.print ("20");
b=20;
}
if(str[0] ==27
) {
lcd.clear ();
lcd.setCursor(0,0);
lcd.print("milk");
delay (500);
lcd.setCursor(0,1);
lcd.print ("50");
c=50;
}
d=a+b+c;
//
Serial.println();
delay(1000);
}
val = digitalRead(inPin);
if (val == HIGH) {
lcd.print ("total=");
lcd.print (d);
// lcd.print('\n');
}
else {
lcd.print(" ");
}
}