Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.82 KB | None | 0 0
  1. #include <Servo.h>
  2. #include <Wire.h>
  3. #include <LiquidCrystal_I2C.h>
  4.  
  5. #include <SPI.h>
  6. #include <MFRC522.h>
  7.  
  8. #define RST_PIN 9 // Configurable, see typical pin layout above
  9. #define SS_PIN 10 // Configurable, see typical pin layout above
  10.  
  11. MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
  12.  
  13.  
  14. Servo myservo; //Servo In
  15.  
  16. typedef struct Data
  17. {
  18. unsigned long int uID;
  19. int userBalance;
  20. String Name;
  21. String carModel;
  22. int uCost;
  23. } Data;
  24.  
  25. Data DataOfUser[5];
  26. int curUser = 0;
  27.  
  28. //Intitalising User
  29. void initUser()
  30. {
  31. DataOfUser[0].uID = 4294944795;
  32. DataOfUser[0].userBalance = 1000;
  33. DataOfUser[0].Name = "SAH";
  34. DataOfUser[0].carModel = "Tesla";
  35. DataOfUser[0].uCost = 100;
  36.  
  37. DataOfUser[1].uID = 4294961165;
  38. DataOfUser[1].userBalance = 150;
  39. DataOfUser[1].Name = "FF";
  40. DataOfUser[1].carModel = "Toyotoa";
  41. DataOfUser[1].uCost = 60;
  42.  
  43. curUser = 2;
  44.  
  45. }
  46.  
  47.  
  48.  
  49.  
  50. void OpentheGate()
  51. {
  52. for (int i = 10; i <= 70; i += 1) // goes from 0 degrees to 180 degrees
  53. {
  54. // in steps of 1 degree
  55. myservo.write(i); // tell servo to go to position in variable 'pos'
  56. delay(15); // waits 15ms for the servo to reach the position
  57. // Serial.println(i);
  58.  
  59. }
  60.  
  61. }
  62.  
  63. void ClosetheGate()
  64. {
  65. for (int i = 70; i >= 10; i -= 1) // goes from 180 degrees to 0 degrees
  66. {
  67. myservo.write(i); // tell servo to go to position in variable 'pos'
  68. delay(15); // waits 15ms for the servo to reach the position
  69. }
  70.  
  71.  
  72. }
  73.  
  74.  
  75. // Set the LCD address to 0x27 for a 16 chars and 2 line display
  76. LiquidCrystal_I2C lcd(0x27, 16, 2);
  77.  
  78.  
  79. unsigned long getID()
  80. {
  81. if ( ! mfrc522.PICC_ReadCardSerial()) //Since a PICC placed get Serial and continue
  82. {
  83. return -1;
  84. }
  85. unsigned long hex_num;
  86. hex_num = mfrc522.uid.uidByte[0] << 24;
  87. hex_num += mfrc522.uid.uidByte[1] << 16;
  88. hex_num += mfrc522.uid.uidByte[2] << 8;
  89. hex_num += mfrc522.uid.uidByte[3];
  90. mfrc522.PICC_HaltA(); // Stop reading
  91. return hex_num;
  92. }
  93.  
  94. void StartDisplay(){
  95. lcd.clear();
  96. delay(1000);
  97. lcd.setCursor(5,1);
  98. lcd.print("A Project");
  99. delay(1600);
  100.  
  101. lcd.clear();
  102. lcd.setCursor(8,1);
  103. lcd.print("of");
  104. delay(1200);
  105.  
  106. lcd.clear();
  107. lcd.setCursor(7,1);
  108. lcd.print("GRAND");
  109. delay(1200);
  110.  
  111. lcd.clear();
  112. lcd.setCursor(6,1);
  113. lcd.print("ROBOTICS");
  114. delay(1200);
  115.  
  116. lcd.clear();
  117. lcd.setCursor(4,1);
  118. lcd.print("DEMOSTRATION");
  119. delay(1200);
  120.  
  121. lcd.clear();
  122. lcd.setCursor(7,1);
  123. lcd.print("CLASS");
  124. delay(2000);
  125. lcd.clear();
  126. }
  127.  
  128.  
  129. void setup()
  130. {
  131. Serial.begin(9600); // Initialize serial communications with the PC
  132.  
  133. SPI.begin(); // Init SPI bus
  134. mfrc522.PCD_Init(); // Init MFRC522
  135. delay(4); // Optional delay. Some board do need more time after init to be ready, see Readme
  136. myservo.attach(7);
  137. mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
  138. Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
  139. // initialize the LCD
  140. lcd.begin();
  141. initUser();
  142. myservo.write(10);
  143. StartDisplay();
  144. }
  145.  
  146.  
  147. void welcomeMessage()
  148. {
  149. lcd.clear();
  150. lcd.setCursor(0, 1);
  151. lcd.print(" Welcome to STCS");
  152.  
  153. }
  154.  
  155. void goodBye()
  156. {
  157. lcd.clear();
  158. lcd.setCursor(0, 1);
  159. lcd.print(" Good Bye!");
  160. ClosetheGate();
  161. delay(2000);
  162.  
  163.  
  164. }
  165. void displayUserData(int id)
  166. {
  167. delay(1000);
  168. lcd.clear();
  169.  
  170.  
  171. if (DataOfUser[id].userBalance < DataOfUser[id].uCost )
  172. {
  173. lcd.setCursor(0,1);
  174. lcd.print("Insufficient Balance");
  175. lcd.setCursor(0, 2);
  176. lcd.print(" Please Recharge!");
  177. delay(3000);
  178. return;
  179. }
  180.  
  181. DataOfUser[id].userBalance -= DataOfUser[id].uCost;
  182. lcd.setCursor(0, 1);
  183. lcd.print("Name: " + DataOfUser[id].Name);
  184. lcd.setCursor(0, 2);
  185. lcd.print("Vehicle: " + DataOfUser[id].carModel);
  186. delay(2000);
  187. lcd.clear();
  188.  
  189. lcd.setCursor(0, 1);
  190. lcd.print("Fee: ");
  191. lcd.print(DataOfUser[id].uCost, DEC);
  192. lcd.setCursor(0,2);
  193. lcd.print("Balance: ");
  194. lcd.print(DataOfUser[id].userBalance, DEC);
  195. OpentheGate();
  196. delay(5000);
  197. goodBye();
  198.  
  199.  
  200. }
  201.  
  202. void TollCollect(unsigned long int id)
  203. {
  204.  
  205. for (int i = 0; i < curUser; i++)
  206. {
  207. Serial.println(DataOfUser[i].uID);
  208. if (DataOfUser[i].uID == id)
  209. {
  210.  
  211. displayUserData(i);
  212. }
  213. }
  214.  
  215. }
  216.  
  217. void loop()
  218. {
  219. welcomeMessage();
  220.  
  221. if (mfrc522.PICC_IsNewCardPresent())
  222. {
  223. unsigned long uid = getID();
  224.  
  225. if (uid != -1)
  226. {
  227. TollCollect(uid);
  228. }
  229. }
  230.  
  231.  
  232. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement