#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
const int bp = 2;
const int lp1 = 4;
const int lp2 = 3;
const int buzz = 5;
int cp =0;
int fp = 0;
int item = 0;
double total = total;
int but = 0;
void setup()
{
pinMode(lp1,OUTPUT);
pinMode(lp2,OUTPUT);
pinMode(bp, INPUT);
pinMode(buzz,OUTPUT);
Serial.begin(9600); // Initiate a serial communication
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
}
void loop()
{
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
String content= "";
byte letter;
for (byte i = 0; i < mfrc522.uid.size; i++)
{
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
Serial.println();
Serial.print(" ");
content.toUpperCase();
if (content.substring(1) == "A9 BB A0 B2") //change here the UID of the card/cards that you want to give access
{
return;
Serial.println("Welcome");
Serial.println("You can start shopping...");
Serial.println();
Serial.println("|");
Serial.println();
delay(2000);
//delay(3000)
}
int but = digitalRead(bp);
if ((content.substring(1) == "99 F6 B5 6D")&&(but == LOW))
{
return;
Serial.println("PRODUCT ADDED:-");
Serial.println();
Serial.println("|");
Serial.println(" REDBULL ");
Serial.println();
Serial.println("|");
total = total + 90;
cp++;
digitalWrite(lp1,HIGH);
delay(200);
digitalWrite(lp1, LOW);
Serial.println("QTY :");
Serial.println();
Serial.println("|");
Serial.println(cp);
Serial.println();
Serial.println("|");
Serial.println();
delay(200);
}
else if ((content.substring(1) == "99 F6 B5 6D")&&(but == HIGH ))
{
if(cp > 0)
{
return;
Serial.println("PRODUCT REMOVED");
Serial.println();
Serial.println("|");
Serial.println(" REDBULL ");
Serial.println();
Serial.println("|");
total = total - 20;
cp--;
Serial.println("QTY :");
Serial.println();
Serial.println("|");
Serial.println(cp);
Serial.println();
Serial.println("|");
digitalWrite(lp2,HIGH);
delay(300);
digitalWrite(lp2,LOW);
tone(buzz,1000);
delay(300);
noTone(buzz);
Serial.println();
delay(200);
}
else
{
Serial.println("product not in cart");
Serial.println();
delay(200);
}
}
if((content.substring(1) == "89 ED 88 9C") && (but == LOW))
{
Serial.println("PRODUCT ADDED:-");
Serial.println();
Serial.println("|");
Serial.println(" BINGO ");
Serial.println();
Serial.println("|");
Serial.println();
total = total + 20;
fp++;
Serial.println("QTY:");
Serial.println();
Serial.println("|");
Serial.println(fp);
Serial.println();
Serial.println("|");
digitalWrite(lp1,HIGH);
delay(200);
digitalWrite(lp1, LOW);
Serial.println();
delay(200);
}
else if((content.substring(1) == "89 ED 88 9C") && (but == HIGH ))
{
if(fp > 0)
{
Serial.println("PRODUCT REMOVED:-");
Serial.println();
Serial.println("|");
Serial.println(" BINGO ");
Serial.println();
Serial.println("|");
total = total - 20;
fp--;
Serial.println("QTY:");
Serial.println();
Serial.println("|");
Serial.println(fp);
Serial.println();
Serial.println("|");
digitalWrite(lp2,HIGH);
delay(300);
digitalWrite(lp2, LOW);
tone(buzz,1000);
delay(300);
noTone(buzz);
Serial.println();
delay(200);
}
else
{
Serial.println("item not in cart");
Serial.println();
delay(200);
}
}
int items = cp+fp ;
Serial.println(" Total number of items in the cart:-");
Serial.println();
Serial.println("|");
Serial.println(items);
Serial.println();
Serial.println("|");
Serial.println("The total price to be paid is:- ");
Serial.println();
Serial.println("|");
Serial.println(total);
Serial.println();
Serial.println("|");
Serial.println();
delay(300);
}