Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- #include <SPI.h>
- #include <MFRC522.h>
- #define RST_PIN 9 // Configurable, see typical pin layout above
- #define SS_PIN 10 // Configurable, see typical pin layout above
- MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
- Servo myservo; //Servo In
- typedef struct Data
- {
- unsigned long int uID;
- int userBalance;
- String Name;
- String carModel;
- int uCost;
- } Data;
- Data DataOfUser[5];
- int curUser = 0;
- //Intitalising User
- void initUser()
- {
- DataOfUser[0].uID = 4294944795;
- DataOfUser[0].userBalance = 1000;
- DataOfUser[0].Name = "SAH";
- DataOfUser[0].carModel = "Tesla";
- DataOfUser[0].uCost = 100;
- DataOfUser[1].uID = 4294961165;
- DataOfUser[1].userBalance = 150;
- DataOfUser[1].Name = "FF";
- DataOfUser[1].carModel = "Toyotoa";
- DataOfUser[1].uCost = 60;
- curUser = 2;
- }
- void OpentheGate()
- {
- for (int i = 10; i <= 70; i += 1) // goes from 0 degrees to 180 degrees
- {
- // in steps of 1 degree
- myservo.write(i); // tell servo to go to position in variable 'pos'
- delay(15); // waits 15ms for the servo to reach the position
- // Serial.println(i);
- }
- }
- void ClosetheGate()
- {
- for (int i = 70; i >= 10; i -= 1) // goes from 180 degrees to 0 degrees
- {
- myservo.write(i); // tell servo to go to position in variable 'pos'
- delay(15); // waits 15ms for the servo to reach the position
- }
- }
- // Set the LCD address to 0x27 for a 16 chars and 2 line display
- LiquidCrystal_I2C lcd(0x27, 16, 2);
- unsigned long getID()
- {
- if ( ! mfrc522.PICC_ReadCardSerial()) //Since a PICC placed get Serial and continue
- {
- return -1;
- }
- unsigned long hex_num;
- hex_num = mfrc522.uid.uidByte[0] << 24;
- hex_num += mfrc522.uid.uidByte[1] << 16;
- hex_num += mfrc522.uid.uidByte[2] << 8;
- hex_num += mfrc522.uid.uidByte[3];
- mfrc522.PICC_HaltA(); // Stop reading
- return hex_num;
- }
- void StartDisplay(){
- lcd.clear();
- delay(1000);
- lcd.setCursor(5,1);
- lcd.print("A Project");
- delay(1600);
- lcd.clear();
- lcd.setCursor(8,1);
- lcd.print("of");
- delay(1200);
- lcd.clear();
- lcd.setCursor(7,1);
- lcd.print("GRAND");
- delay(1200);
- lcd.clear();
- lcd.setCursor(6,1);
- lcd.print("ROBOTICS");
- delay(1200);
- lcd.clear();
- lcd.setCursor(4,1);
- lcd.print("DEMOSTRATION");
- delay(1200);
- lcd.clear();
- lcd.setCursor(7,1);
- lcd.print("CLASS");
- delay(2000);
- lcd.clear();
- }
- void setup()
- {
- Serial.begin(9600); // Initialize serial communications with the PC
- SPI.begin(); // Init SPI bus
- mfrc522.PCD_Init(); // Init MFRC522
- delay(4); // Optional delay. Some board do need more time after init to be ready, see Readme
- myservo.attach(7);
- mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
- Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
- // initialize the LCD
- lcd.begin();
- initUser();
- myservo.write(10);
- StartDisplay();
- }
- void welcomeMessage()
- {
- lcd.clear();
- lcd.setCursor(0, 1);
- lcd.print(" Welcome to STCS");
- }
- void goodBye()
- {
- lcd.clear();
- lcd.setCursor(0, 1);
- lcd.print(" Good Bye!");
- ClosetheGate();
- delay(2000);
- }
- void displayUserData(int id)
- {
- delay(1000);
- lcd.clear();
- if (DataOfUser[id].userBalance < DataOfUser[id].uCost )
- {
- lcd.setCursor(0,1);
- lcd.print("Insufficient Balance");
- lcd.setCursor(0, 2);
- lcd.print(" Please Recharge!");
- delay(3000);
- return;
- }
- DataOfUser[id].userBalance -= DataOfUser[id].uCost;
- lcd.setCursor(0, 1);
- lcd.print("Name: " + DataOfUser[id].Name);
- lcd.setCursor(0, 2);
- lcd.print("Vehicle: " + DataOfUser[id].carModel);
- delay(2000);
- lcd.clear();
- lcd.setCursor(0, 1);
- lcd.print("Fee: ");
- lcd.print(DataOfUser[id].uCost, DEC);
- lcd.setCursor(0,2);
- lcd.print("Balance: ");
- lcd.print(DataOfUser[id].userBalance, DEC);
- OpentheGate();
- delay(5000);
- goodBye();
- }
- void TollCollect(unsigned long int id)
- {
- for (int i = 0; i < curUser; i++)
- {
- Serial.println(DataOfUser[i].uID);
- if (DataOfUser[i].uID == id)
- {
- displayUserData(i);
- }
- }
- }
- void loop()
- {
- welcomeMessage();
- if (mfrc522.PICC_IsNewCardPresent())
- {
- unsigned long uid = getID();
- if (uid != -1)
- {
- TollCollect(uid);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement