Geordie9969

Parking System

Jun 13th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.22 KB | None | 0 0
  1. #include "MaxMatrix.h"
  2. #include "avr/pgmspace.h"
  3. #include <Servo.h>
  4. #include <SPI.h>
  5. #include <RFID.h>
  6. #include <EEPROM.h>
  7. #include <LiquidCrystal_I2C.h>
  8. #include <Wire.h>
  9. #include "Wire.h"
  10. #include "RTClib.h"
  11. #include <EEPROM.h>
  12.  
  13. int postiocc = 0; //posti occupati nel parcheggio
  14. int postilib = 5; //posti liberi nel parcheggio
  15. int address = 0;
  16. byte value;
  17.  
  18. PROGMEM const unsigned char CH[] = {
  19. 3, 8, B00000000, B00000000, B00000000, B00000000, B00000000, // space
  20. 1, 8, B01011111, B00000000, B00000000, B00000000, B00000000, // !
  21. 3, 8, B00000011, B00000000, B00000011, B00000000, B00000000, // "
  22. 5, 8, B00010100, B00111110, B00010100, B00111110, B00010100, // #
  23. 4, 8, B00100100, B01101010, B00101011, B00010010, B00000000, // $
  24. 5, 8, B01100011, B00010011, B00001000, B01100100, B01100011, // %
  25. 5, 8, B00110110, B01001001, B01010110, B00100000, B01010000, // &
  26. 1, 8, B00000011, B00000000, B00000000, B00000000, B00000000, // '
  27. 3, 8, B00011100, B00100010, B01000001, B00000000, B00000000, // (
  28. 3, 8, B01000001, B00100010, B00011100, B00000000, B00000000, // )
  29. 5, 8, B00101000, B00011000, B00001110, B00011000, B00101000, // *
  30. 5, 8, B00001000, B00001000, B00111110, B00001000, B00001000, // +
  31. 2, 8, B10110000, B01110000, B00000000, B00000000, B00000000, // ,
  32. 4, 8, B00001000, B00001000, B00001000, B00001000, B00000000, // -
  33. 2, 8, B01100000, B01100000, B00000000, B00000000, B00000000, // .
  34. 4, 8, B01100000, B00011000, B00000110, B00000001, B00000000, // /
  35. 4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // 0
  36. 3, 8, B01000010, B01111111, B01000000, B00000000, B00000000, // 1
  37. 4, 8, B01100010, B01010001, B01001001, B01000110, B00000000, // 2
  38. 4, 8, B00100010, B01000001, B01001001, B00110110, B00000000, // 3
  39. 4, 8, B00011000, B00010100, B00010010, B01111111, B00000000, // 4
  40. 4, 8, B00100111, B01000101, B01000101, B00111001, B00000000, // 5
  41. 4, 8, B00111110, B01001001, B01001001, B00110000, B00000000, // 6
  42. 4, 8, B01100001, B00010001, B00001001, B00000111, B00000000, // 7
  43. 4, 8, B00110110, B01001001, B01001001, B00110110, B00000000, // 8
  44. 4, 8, B00000110, B01001001, B01001001, B00111110, B00000000, // 9
  45. 2, 8, B01010000, B00000000, B00000000, B00000000, B00000000, // :
  46. 2, 8, B10000000, B01010000, B00000000, B00000000, B00000000, // ;
  47. 3, 8, B00010000, B00101000, B01000100, B00000000, B00000000, // <
  48. 3, 8, B00010100, B00010100, B00010100, B00000000, B00000000, // =
  49. 3, 8, B01000100, B00101000, B00010000, B00000000, B00000000, // >
  50. 4, 8, B00000010, B01011001, B00001001, B00000110, B00000000, // ?
  51. 5, 8, B00111110, B01001001, B01010101, B01011101, B00001110, // @
  52. 4, 8, B01111110, B00010001, B00010001, B01111110, B00000000, // A
  53. 4, 8, B01111111, B01001001, B01001001, B00110110, B00000000, // B
  54. 4, 8, B00111110, B01000001, B01000001, B00100010, B00000000, // C
  55. 4, 8, B01111111, B01000001, B01000001, B00111110, B00000000, // D
  56. 4, 8, B01111111, B01001001, B01001001, B01000001, B00000000, // E
  57. 4, 8, B01111111, B00001001, B00001001, B00000001, B00000000, // F
  58. 4, 8, B00111110, B01000001, B01001001, B01111010, B00000000, // G
  59. 4, 8, B01111111, B00001000, B00001000, B01111111, B00000000, // H
  60. 3, 8, B01000001, B01111111, B01000001, B00000000, B00000000, // I
  61. 4, 8, B00110000, B01000000, B01000001, B00111111, B00000000, // J
  62. 4, 8, B01111111, B00001000, B00010100, B01100011, B00000000, // K
  63. 4, 8, B01111111, B01000000, B01000000, B01000000, B00000000, // L
  64. 5, 8, B01111111, B00000010, B00001100, B00000010, B01111111, // M
  65. 5, 8, B01111111, B00000100, B00001000, B00010000, B01111111, // N
  66. 4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // O
  67. 4, 8, B01111111, B00001001, B00001001, B00000110, B00000000, // P
  68. 4, 8, B00111110, B01000001, B01000001, B10111110, B00000000, // Q
  69. 4, 8, B01111111, B00001001, B00001001, B01110110, B00000000, // R
  70. 4, 8, B01000110, B01001001, B01001001, B00110010, B00000000, // S
  71. 5, 8, B00000001, B00000001, B01111111, B00000001, B00000001, // T
  72. 4, 8, B00111111, B01000000, B01000000, B00111111, B00000000, // U
  73. 5, 8, B00001111, B00110000, B01000000, B00110000, B00001111, // V
  74. 5, 8, B00111111, B01000000, B00111000, B01000000, B00111111, // W
  75. 5, 8, B01100011, B00010100, B00001000, B00010100, B01100011, // X
  76. 5, 8, B00000111, B00001000, B01110000, B00001000, B00000111, // Y
  77. 4, 8, B01100001, B01010001, B01001001, B01000111, B00000000, // Z
  78. 2, 8, B01111111, B01000001, B00000000, B00000000, B00000000, // [
  79. 4, 8, B00000001, B00000110, B00011000, B01100000, B00000000, // \ backslash
  80. 2, 8, B01000001, B01111111, B00000000, B00000000, B00000000, // ]
  81. 3, 8, B00000010, B00000001, B00000010, B00000000, B00000000, // hat
  82. 4, 8, B01000000, B01000000, B01000000, B01000000, B00000000, // _
  83. 2, 8, B00000001, B00000010, B00000000, B00000000, B00000000, // `
  84. 4, 8, B00100000, B01010100, B01010100, B01111000, B00000000, // a
  85. 4, 8, B01111111, B01000100, B01000100, B00111000, B00000000, // b
  86. 4, 8, B00111000, B01000100, B01000100, B00101000, B00000000, // c
  87. 4, 8, B00111000, B01000100, B01000100, B01111111, B00000000, // d
  88. 4, 8, B00111000, B01010100, B01010100, B00011000, B00000000, // e
  89. 3, 8, B00000100, B01111110, B00000101, B00000000, B00000000, // f
  90. 4, 8, B10011000, B10100100, B10100100, B01111000, B00000000, // g
  91. 4, 8, B01111111, B00000100, B00000100, B01111000, B00000000, // h
  92. 3, 8, B01000100, B01111101, B01000000, B00000000, B00000000, // i
  93. 4, 8, B01000000, B10000000, B10000100, B01111101, B00000000, // j
  94. 4, 8, B01111111, B00010000, B00101000, B01000100, B00000000, // k
  95. 3, 8, B01000001, B01111111, B01000000, B00000000, B00000000, // l
  96. 5, 8, B01111100, B00000100, B01111100, B00000100, B01111000, // m
  97. 4, 8, B01111100, B00000100, B00000100, B01111000, B00000000, // n
  98. 4, 8, B00111000, B01000100, B01000100, B00111000, B00000000, // o
  99. 4, 8, B11111100, B00100100, B00100100, B00011000, B00000000, // p
  100. 4, 8, B00011000, B00100100, B00100100, B11111100, B00000000, // q
  101. 4, 8, B01111100, B00001000, B00000100, B00000100, B00000000, // r
  102. 4, 8, B01001000, B01010100, B01010100, B00100100, B00000000, // s
  103. 3, 8, B00000100, B00111111, B01000100, B00000000, B00000000, // t
  104. 4, 8, B00111100, B01000000, B01000000, B01111100, B00000000, // u
  105. 5, 8, B00011100, B00100000, B01000000, B00100000, B00011100, // v
  106. 5, 8, B00111100, B01000000, B00111100, B01000000, B00111100, // w
  107. 5, 8, B01000100, B00101000, B00010000, B00101000, B01000100, // x
  108. 4, 8, B10011100, B10100000, B10100000, B01111100, B00000000, // y
  109. 3, 8, B01100100, B01010100, B01001100, B00000000, B00000000, // z
  110. 3, 8, B00001000, B00110110, B01000001, B00000000, B00000000, // {
  111. 1, 8, B01111111, B00000000, B00000000, B00000000, B00000000, // |
  112. 3, 8, B01000001, B00110110, B00001000, B00000000, B00000000, // }
  113. 4, 8, B00001000, B00000100, B00001000, B00000100, B00000000, // ~
  114. };
  115.  
  116. /*MODULO OROLOGIO*/
  117. RTC_DS1307 RTC;
  118.  
  119.  
  120. int data = 2; // DIN pin of MAX7219 module
  121. int load = 12; // CS pin of MAX7219 module
  122. int clock = 13; // CLK pin of MAX7219 module
  123. int maxInUse = 2; //how many MAX7219 are connected
  124.  
  125. MaxMatrix m(data, load, clock, maxInUse); // define Library
  126. byte buffer[10];
  127. char string1[] = "3 posti disponibili "; // Scrolling Text
  128. char string2[] = "2 posti disponibili "; // Scrolling Text
  129. char string3[] = "1 posto disponibile "; // Scrolling Text
  130. char string4[] = "NESSUN POSTO DISPONIBILE "; // Scrolling Text
  131.  
  132. /*FOTOCELLULA APERTURA/CHIUSURA*/
  133. const int fotoresistenza1 = A0;//pin fotoresistenza entrata
  134. const int fotoresistenza2 = A1;//pin fotoresistenza uscita
  135. int lum = 0; //variabile del valore che proviene dalla fotoresistenza entrata
  136. int lum2 = 0; //variabile del valore che proviene dalla fotoresistenza uscita
  137. Servo servo1; // servo motore per la sbarra entrata
  138. Servo servo2; // servo motore per la sbarra chiusura
  139. int pos = 5; //variabile per lo stato del servo
  140. int pos2 = 5; //variabile per lo stato del servo2
  141. const int PM = 23; //pulsante
  142. int valpm = 0; //variabili di appoggio pulsante
  143. int old_valpm = 0;
  144. int statepm = 0;
  145. /*RFID APERTURA*/
  146. #define SS_PIN 26 //pin ss
  147. #define RST_PIN 28 //pin rst
  148. // Codice della prima chiave
  149. #define key1num0 4
  150. #define key1num1 208
  151. #define key1num2 239
  152. #define key1num3 165
  153. #define key1num4 158
  154. //codice della seconda chiave
  155. #define key2num0 196
  156. #define key2num1 109
  157. #define key2num2 227
  158. #define key2num3 233
  159. #define key2num4 163
  160.  
  161. RFID rfid(SS_PIN, RST_PIN);
  162. int sernum0;
  163. int sernum1;
  164. int sernum2;
  165. int sernum3;
  166. int sernum4;
  167. int i = 0; //contatori accessi
  168.  
  169. /*DISPLAY ENTRATA*/
  170. LiquidCrystal_I2C lcd1(0x3F, 2, 1, 0, 4 , 5, 6, 7, 3, POSITIVE);
  171.  
  172.  
  173. void setup()
  174. {
  175. Serial.begin(9600);
  176. m.init(); // module MAX7219
  177. m.setIntensity(1); // LED Intensity 0-15
  178. pinMode(PM, INPUT); //pulsante entrata
  179. SPI.begin(); //rfid
  180. rfid.init();//rfid
  181. servo1.attach (22); //sbarra entrata
  182. servo1.write(pos);
  183. servo2.attach (24); //sbarra chiusura
  184. servo2.write(pos2);
  185. Wire.begin();
  186. RTC.begin();
  187. //RTC.adjust(DateTime(2018, 5, 28, 17, 26, 30));
  188. lcd1.begin(16, 2); //display entrata
  189. lcd1.clear();
  190. lcd1.print("Benvenuto");
  191.  
  192. }
  193.  
  194. void loop() {
  195.  
  196.  
  197. }
  198.  
  199.  
  200.  
  201. void tabellone() {
  202. postilib = postilib - postiocc;
  203. if (postilib >= 3) {
  204. printStringWithShift(string1, 100);// Send scrolling Text
  205. }
  206. else {
  207. if (postilib == 2) {
  208. printStringWithShift(string2, 100); // Send scrolling Text
  209. } else {
  210. if (postilib == 1) {
  211. printStringWithShift(string3, 100); // Send scrolling Text
  212. } else {
  213. printStringWithShift(string4, 100); // Send scrolling Text
  214. }
  215. }
  216. }
  217. }
  218. postiocc++;
  219. }
  220. /*void tabellone*/
  221. void printCharWithShift(char c, int shift_speed) {
  222.  
  223. if (c < 32) return;
  224. c -= 32;
  225. memcpy_P(buffer, CH + 7 * c, 7);
  226. m.writeSprite(maxInUse * 8, 0, buffer);
  227. m.setColumn(maxInUse * 8 + buffer[0], 0);
  228.  
  229. for (int i = 0; i < buffer[0] + 1; i++)
  230. {
  231. delay(shift_speed);
  232. m.shiftLeft(false, false);
  233. }
  234.  
  235.  
  236. }
  237. // Extract characters from Scrolling text
  238. void printStringWithShift(char* s, int shift_speed) {
  239. while (*s != 0) {
  240. printCharWithShift(*s, shift_speed);
  241. s++;
  242. }
  243. }
Add Comment
Please, Sign In to add comment