Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1.  
  2. #define Opoznienie 0
  3. #define czyRaport 1
  4.  
  5. // Przypisanie pinow Arduino do wejsc i wyjsc ukladu windy
  6. int Button0 = A0; // Pin dla przycisku przywolania windy na poziom nr 0.
  7.  
  8. int Button1 = A1; // Pin dla przycisku przywolania windy na poziom nr 1.
  9.  
  10. int Button3 = A3; // Pin dla przycisku przywolania windy na poziom nr 3.
  11.  
  12. int Sensor0 = A4; // Pin dla sensora obecnosci windy na poziomie nr 0.
  13.  
  14. int Sensor1 = A5; // Pin dla sensora obecnosci windy na poziomie nr 1.
  15.  
  16. int Sensor3 = 13;// Pin dla sensora obecnosci windy na poziomie nr 3.
  17.  
  18. int OutputQ1Pin=5;// Pin dla Control Signal of Relay 3 / Output Signal Q1 / Forward/Reverse Signal
  19.  
  20. int OutputQ2Pin=4;// Pin dla Control Signal of Relay 4 / Output Signal Q2 / Start/Stop Signal
  21.  
  22.  
  23.  
  24. //Zmienne globalne
  25.  
  26.  
  27. boolean Q1 = 1;//Forward/Reverse Control Signal Relay 3
  28.  
  29. boolean Q2 = 0;//Start/Stop Control Signal Relay 4
  30.  
  31. boolean I1 = 0;//Odczyt z "Przycisk żądanie 0-go poziomu"
  32.  
  33. boolean I2 = 0;//Odczyt z "Przycisk żądanie 1-go poziomu"
  34.  
  35. boolean I4 = 0;//Odczyt z "Przycisk żądanie 3-go poziomu"
  36.  
  37. boolean I5 = 0;//Odczyt z "Sensor obecności kabiny na 0. poziomie"
  38.  
  39. boolean I6 = 0;//Odczyt z "Sensor obecności kabiny na 1. poziomie"
  40.  
  41. boolean I8 = 0;//Odczyt z "Sensor obecności kabiny na 3. poziomie"
  42.  
  43.  
  44. //Flagi stanow dla chwili t
  45.  
  46.  
  47. boolean M1 = 0;
  48.  
  49. boolean M2 = 0;
  50.  
  51. boolean M3 = 0;
  52.  
  53. boolean M4 = 0;
  54.  
  55. boolean M5 = 0;
  56.  
  57. boolean M6 = 0;
  58.  
  59. boolean M7 = 0;
  60.  
  61. boolean M9 = 0;
  62.  
  63. boolean Mdziesiec = 0;
  64.  
  65.  
  66. //Flagi stanow dla chwili t + 1
  67.  
  68.  
  69. boolean M1p = 0;
  70.  
  71. boolean M2p = 0;
  72.  
  73. boolean M3p = 0;
  74.  
  75. boolean M4p = 0;
  76.  
  77. boolean M5p = 0;
  78.  
  79. boolean M6p = 0;
  80.  
  81. boolean M7p = 0;
  82.  
  83. boolean M9p = 0;
  84.  
  85. boolean Mdziesiecp = 0;
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93. void raport()
  94.  
  95. {
  96.  
  97. Serial.println("Odczyt przyciskow ");
  98.  
  99. Serial.print(I1);
  100.  
  101. Serial.print(I2);
  102.  
  103. Serial.print(I4);
  104.  
  105. Serial.println();
  106.  
  107. Serial.println("Odczyt sensorow ");
  108.  
  109. Serial.print(I5);
  110.  
  111. Serial.print(I6);
  112.  
  113. Serial.print(I8);
  114.  
  115. Serial.println();
  116.  
  117. Serial.println("Stan wewnetrzny (flagi) ");
  118.  
  119. Serial.print(M1);
  120.  
  121. Serial.print(M2);
  122.  
  123. Serial.print(M3);
  124.  
  125. Serial.print(M4);
  126.  
  127. Serial.print(M5);
  128.  
  129. Serial.print(M6);
  130.  
  131. Serial.print(M7);
  132.  
  133. Serial.print(M9);
  134.  
  135. Serial.print(Mdziesiec);
  136.  
  137. Serial.println();
  138.  
  139. Serial.println("Stan wyjsc ");
  140.  
  141. Serial.print(Q1);
  142.  
  143. Serial.print(Q2);
  144.  
  145. Serial.println();
  146.  
  147. }
  148.  
  149.  
  150.  
  151. void odczytWejsc()
  152.  
  153. {
  154.  
  155. I1 = digitalRead(Button0);
  156.  
  157. I2 = digitalRead(Button1);
  158.  
  159. I4 = digitalRead(Button3);
  160.  
  161. I5 = digitalRead(Sensor0);
  162.  
  163. I6 = digitalRead(Sensor1);
  164.  
  165. I8 = digitalRead(Sensor3);
  166.  
  167. }
  168.  
  169.  
  170. void funkcjaPrzejscia()
  171. {
  172.  
  173. //Obliczanie nowych wartosci funkcji przejsc stanow
  174.  
  175. M1p = (M1 & !I1 & !I2) | (M7 & I8) | (Mdziesiec & I8);
  176.  
  177. M2p = (M2 & !I1 & !I4) | (M4 & I6) | (M9 & I6);
  178.  
  179. M3p = (M3 & !I2 & !I4) | (M5 & I5) | (M6 & I5);
  180.  
  181. M4p = (M1 & I2)| (M4 & !I6);
  182.  
  183. M5p = (M1 & I1) | (M5 & !I5) | !(M1 | M2 | M3 | M4 | M5 | M6 | M7 | M9 | Mdziesiec);
  184.  
  185. M6p = (M2 & I1) | (M6 & !I5);
  186.  
  187. M7p = (M2 & I4) | (M7 & !I8);
  188.  
  189. M9p = (M3 & I2) | (M9 & !I6);
  190.  
  191. Mdziesiecp = (M3 & I4) | (Mdziesiec & !I8);
  192.  
  193.  
  194. M1 = M1p;
  195.  
  196. M2 = M2p;
  197.  
  198. M3 = M3p;
  199.  
  200. M4 = M4p;
  201.  
  202. M5 = M5p;
  203.  
  204. M6 = M6p;
  205.  
  206. M7 = M7p;
  207.  
  208. M9 = M9p;
  209.  
  210. Mdziesiec = Mdziesiecp;
  211.  
  212. }
  213.  
  214.  
  215.  
  216. void funkcjaWyjscia()
  217.  
  218. {
  219.  
  220. Q1 = M4 | M5 | M6;
  221.  
  222. Q2 = M1 | M2 | M3;
  223.  
  224.  
  225. }
  226.  
  227.  
  228.  
  229. void zapisWyjscia()
  230.  
  231. {
  232.  
  233. digitalWrite(OutputQ1Pin,Q1);
  234.  
  235. digitalWrite(OutputQ2Pin,Q2);
  236.  
  237. }
  238.  
  239.  
  240. void setup()
  241.  
  242. {
  243.  
  244. pinMode(Button0, INPUT);
  245.  
  246. pinMode(Button1, INPUT);
  247.  
  248. pinMode(Button3, INPUT);
  249.  
  250. pinMode(Sensor0, INPUT);
  251.  
  252. pinMode(Sensor1, INPUT);
  253.  
  254. pinMode(Sensor3, INPUT);
  255.  
  256. pinMode(OutputQ1Pin, OUTPUT);
  257.  
  258. pinMode(OutputQ2Pin, OUTPUT);
  259.  
  260. Serial.begin(9600);
  261.  
  262. Serial.println("Koniec wykonywania Setup");
  263.  
  264. }
  265.  
  266.  
  267.  
  268. void loop()
  269.  
  270. {
  271.  
  272. odczytWejsc();
  273.  
  274. funkcjaPrzejscia();
  275.  
  276. funkcjaWyjscia();
  277.  
  278. zapisWyjscia();
  279.  
  280. if (czyRaport == 1)
  281. raport();
  282.  
  283. delay(Opoznienie);
  284.  
  285. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement