Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.41 KB | None | 0 0
  1.  
  2. #include <Time.h>
  3. #include <TimeLib.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <LiquidCrystal.h> //Dołączenie bilbioteki
  7. LiquidCrystal lcd(A0, A1, A2, A3, A4, A5); //Informacja o podłączeniu nowego wyświetlacza
  8. #include<math.h>
  9. #include "Keypad.h"
  10.  
  11. const byte ROWS = 4; //four rows
  12. const byte COLS = 4; //three columns
  13. char keys[ROWS][COLS] = {
  14. { '1','2','3' , 'A' },
  15. { '4','5','6' , 'B' },
  16. { '7','8','9' , 'C' },
  17. { '*','0','#' , 'D' }
  18. };
  19. byte rowPins[ROWS] = { 9, 8, 7 , 6 }; //Piny, do których podłączamy wyprowadzenia od rzędów
  20. byte colPins[COLS] = { 5, 4, 3, 2 }; //Piny, do których kolumn wyprowadzenia od rzędów
  21. Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
  22.  
  23. int wyn_Mno, k = 0, pojemnik1 = 0, pojemnik2 = 0, wpis_int = 0, wx = 0, PIERWSZA_LICZBA = 0, DRUGA_LICZBA = 0, ILOCZYN = 0;
  24. int x = 0, klucz = 0, buff;
  25. int a = 0,flash=0;
  26. bool access = false, boolowskie_gowno = false,blinker,bomb_has_been_planted=false;
  27. char key;
  28. char wpis1[4], wpis2[3];
  29. unsigned char i, j;
  30. time_t t;
  31. int minuty = 10;
  32. int sekundy = 00, delta_sekund = 0, w = 0;
  33. String tekst;
  34. void czas(String tekst)
  35. {
  36. time_t t = now();
  37. delta_sekund = (sekundy - second(t));
  38. if (delta_sekund<0)
  39. {
  40. delta_sekund += 59;
  41. }
  42.  
  43. lcd.setCursor(9, 0);
  44. if ((minute(t) != w) || (delta_sekund == 9)) //POTRZEBNE DO ODSWIERZENIA KODU PO UPLYWIE MINUTY
  45. {
  46. lcd.clear();
  47. lcd.setCursor(0, 0);
  48. lcd.print(tekst);
  49. w = minute(t);
  50. lcd.setCursor(9, 0);
  51. }
  52.  
  53. lcd.print(minuty - minute(t));
  54. lcd.print(":");
  55. lcd.print(delta_sekund);
  56. }
  57. void buzzerOn()
  58. {
  59. int out = 10;//DO BUZZERA
  60.  
  61. for (int i = 0; i <80; i++)
  62. { // number of cycles to sound
  63. digitalWrite(out, HIGH); // turn buzzer ON
  64. delay(1);// Delay 1ms set frequency 1
  65. digitalWrite(out, LOW); // turn buzzer OFF
  66. delay(1);// delay ms
  67. }
  68. for (int i = 0; i <100; i++)
  69. { // number of cycles to sound
  70. digitalWrite(out, HIGH); // turn buzzer ON
  71. delay(2);// delay 2ms set frequency 2
  72. digitalWrite(out, LOW); // turn buzzer OFF
  73. delay(2);// delay 2ms
  74. }
  75. }
  76. void Bang()
  77. {
  78. pinMode(13, OUTPUT);//TO OD GLOSNIKA
  79. digitalWrite(13, HIGH);//TO OD GOLSNIKA
  80. }
  81. void redLED(bool OnOf) //12PIN
  82. {
  83. pinMode(12, OUTPUT); //
  84. if(OnOf==true)
  85. {
  86. digitalWrite(12, HIGH);
  87. }
  88. else
  89. {
  90. digitalWrite(12, LOW);
  91. }
  92. }
  93. void blueLED(bool OnOf)
  94. {
  95. pinMode(11, OUTPUT); // NIEBIESKI
  96. if(OnOf==true)
  97. {
  98. digitalWrite(11, HIGH); //NIEBIESKI
  99. }
  100. else
  101. {
  102. digitalWrite(11, LOW); //NIEBIESKI
  103. }
  104. }
  105. void mruganie(bool kolor,bool blinker)
  106. {
  107.  
  108. if(blinker==true)
  109. {
  110. flash++;
  111. flash = flash % 100;
  112. if ((flash >= 0) && (flash <= 50))
  113. {
  114. if (kolor == true)
  115. {
  116. redLED(true);
  117. }
  118. else
  119. {
  120. blueLED(true);
  121. }
  122. }
  123. else
  124. {
  125. if (kolor == true)
  126. {
  127. redLED(false);
  128. }
  129. else
  130. {
  131. blueLED(false);
  132. }
  133. }
  134. }
  135. }
  136. void setup()////////////////////////////////!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!SETUP
  137. {
  138. PIERWSZA_LICZBA = 0;
  139. Serial.begin(9600);
  140. a = now();
  141. pojemnik1 = 0;
  142.  
  143. pinMode(10, OUTPUT); //Konfiguracja 10 jako wyjście
  144.  
  145. lcd.begin(16, 2); //Deklaracja typu
  146. lcd.setCursor(0, 0); //Ustawienie kursora
  147. lcd.blink(); //Włącznie kursora
  148. lcd.print("PODAJ A"); //Wyświetlenie tekstu
  149. czas(tekst);
  150. lcd.setCursor(0, 1); //Ustawienie kursora
  151. lcd.print("<0;31>");
  152. time_t t = now();
  153. delta_sekund = (sekundy - second(t)) % 60;
  154. }
  155.  
  156. void loop()//////////////////!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!LOOOOOOOOOP
  157. {
  158. if (bomb_has_been_planted==false)
  159. {
  160. mruganie(true,true);
  161. }
  162. else
  163. {
  164. redLED(true);
  165. }
  166. key = keypad.getKey();
  167. czas(tekst);
  168. if ((PIERWSZA_LICZBA == 0) || (DRUGA_LICZBA == 0))
  169. {
  170.  
  171. if (key != NO_KEY)
  172. {
  173. //buzzerOn();
  174. wpis1[k] = key - '0';
  175. wpis_int = (int)wpis1[k];
  176. lcd.setCursor(8, 1);
  177.  
  178. if (k == 1)
  179. {
  180. lcd.setCursor(9, 1);
  181. }
  182. lcd.print(wpis_int);
  183. delay(300);
  184. x += wpis_int*pow(10, 1 - k);
  185. Serial.print(x);
  186. Serial.print("\n");
  187. k++;
  188. if (x >= 31)
  189. {
  190. x = 31;
  191. }
  192. if (k == 2)
  193. {
  194. if (PIERWSZA_LICZBA != 0)
  195. {
  196. DRUGA_LICZBA = x;
  197. }
  198. else
  199. {
  200. PIERWSZA_LICZBA = x;//nowa zmienna
  201. }
  202. x = 0;
  203. k = 0;
  204.  
  205. lcd.clear();
  206. lcd.setCursor(0, 0);
  207. lcd.print("Podaj B");
  208. lcd.setCursor(0, 1); //Ustawienie kursora
  209. lcd.print("<0;31>");
  210.  
  211. if ((PIERWSZA_LICZBA != 0) && (DRUGA_LICZBA != 0))
  212. {
  213. x = 0;//pewnie zbędne
  214. k = 0;//pewnie zbędne
  215. lcd.clear();
  216. lcd.setCursor(0, 1);
  217. lcd.print(PIERWSZA_LICZBA);
  218. lcd.print("*");
  219. lcd.print(DRUGA_LICZBA);
  220. lcd.print("=");
  221. ILOCZYN = PIERWSZA_LICZBA*DRUGA_LICZBA;
  222. access = true;
  223. //lcd.print(ILOCZYN);
  224. }
  225. }
  226. }
  227.  
  228. }
  229. if (access == true)
  230. {
  231. if (boolowskie_gowno == true)
  232. {
  233. if (key != NO_KEY)
  234. {
  235. Serial.print("boolowskie_gowno == true\n");
  236. wpis1[k] = key - '0';
  237. wpis_int = (int)wpis1[k];
  238. x += wpis_int*pow(10, 2 - k);
  239. lcd.setCursor(7 + k, 1); //Ustawienie kursora
  240. lcd.print(wpis_int);
  241. k++;
  242. Serial.println(x + 1);
  243. Serial.print(" access\n");
  244. if (k == 3)
  245. {
  246. wyn_Mno = x + 1;
  247. x = 0;
  248. k = 0;
  249. if (wyn_Mno == ILOCZYN)
  250. {
  251. delay(250);
  252. lcd.clear();
  253. lcd.setCursor(0, 0);
  254. lcd.print("Bomb has");
  255. lcd.setCursor(0, 1);
  256. lcd.print("been planted.");
  257. delay(1000);
  258. access = false;
  259. bomb_has_been_planted=true;
  260. }
  261. else
  262. {
  263. Serial.println("ZLE HASLO");
  264. delay(250);
  265. lcd.clear();
  266. lcd.setCursor(0, 1);
  267. lcd.print(PIERWSZA_LICZBA);
  268. lcd.print("*");
  269. lcd.print(DRUGA_LICZBA);
  270. lcd.print("=");
  271. }
  272. }
  273. //mozliwosc dodania "lcd.print(String tekst);"
  274.  
  275. }
  276. }
  277. else
  278. {
  279. boolowskie_gowno = true;
  280. }
  281. }
  282. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement