Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.86 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. #include <Wire.h> //Biblioteka od termometru
  3.  
  4. LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
  5.  
  6.  
  7. void setup() {
  8.   #define LM35 A0 //
  9.   lcd.begin(16, 2);
  10.  
  11.   pinMode(A1, OUTPUT); //Buzzer aktywny
  12.   pinMode(A3, INPUT_PULLUP);//Przycisk do zmiany sekundy(tylko ++)
  13.   pinMode(A4, INPUT_PULLUP);//Przycisk do zmiany minuty(tylko ++)
  14.   pinMode(A5, INPUT_PULLUP);//Przycisk do zmiany godziny(tylko ++)
  15.   pinMode(8,INPUT_PULLUP);//Przycisk do zmiany menu
  16.   pinMode(9,OUTPUT); //Zielony LED
  17.   pinMode(10,OUTPUT); //Czerwony LED
  18.   pinMode(13,INPUT_PULLUP); // Przycisk symulujacy wykrycie dymu
  19. }
  20.  
  21. int hour = 23; //Godzina
  22. int minute = 59; //Minuta
  23. int second = 40; //Sekunda
  24. int year = 2019; //Rok
  25. int month = 12; //Miesiac
  26. int day = 22; //Dzien
  27. float min_temp = 10000.0;
  28. float max_temp = 0.0;
  29. int counter = 0;//Pomocniczna zmienna uzywana do wyswietlana odpowiedniego menu
  30. int counter_ID = 0;//Pomocnicza zmienna uzywana do zmiany INC/DEC
  31.  
  32. void loop() {
  33.   float temperatura = (analogRead(LM35)/10.00);//Odczyt temperatury
  34.   Min_Max(temperatura);//Wyznaczenie MAX/MIN temperatury
  35.   Timer();//Zegar
  36.   if(digitalRead(13) == LOW){ //Jesli wykryjemy dym
  37.     while(digitalRead(13) == LOW){//Gdy trzymamy prrzycisk wykonuje sie tylko ten blok
  38.       Timer();//Zegar
  39.       tone(A1, 1000);
  40.       digitalWrite(9,0);//Zgaszenie zielonej diody
  41.       digitalWrite(10,1);//Zaswiecenie czerwonej diody
  42.       digitalWrite(A1, LOW);
  43.       delay(10);
  44.       digitalWrite(A1, HIGH);
  45.       delay(10);
  46.       lcd.setCursor(0, 0);
  47.       lcd.print("UWAGA UWAGA     ");
  48.       lcd.setCursor(0, 1);
  49.       lcd.print("WYKRYTO ZAGROZENIE     ");
  50.     }
  51.     counter_ID++;//Zmiana DEC/INC
  52.   }
  53.   else{
  54.     noTone(A1);//Wylaczenie buzzera
  55.     digitalWrite(9,1);//Zgaszenie czerwonej diody
  56.     digitalWrite(10,0);//Zapalenie zielonej diody
  57.     int stan = digitalRead(8);//Stan przycisku od zmiany menu
  58.    
  59.     if (stan == LOW){
  60.       while(digitalRead(8) == LOW){ //Jesli przytrzymamy przycisk to i tak zmieni on menu o jedna pozycje
  61.         Timer();//Zegar
  62.       }
  63.       counter++;//Inkrementacja menu
  64.     }
  65.    
  66.     if(counter%3 == 0){//Wyswietlenie aktualnej temperatury i czasu
  67.       int stan_hour = digitalRead(A5); //Zmiana godziny
  68.       int stan_minute = digitalRead(A4); //Zmiana minut
  69.       int stan_second = digitalRead(A3); //Zmiana minut
  70.      
  71.       lcd.setCursor(0, 0); //Ustawienie kursora
  72.       lcd.print("Temp: "+ String(temperatura)+(char)223+"C      "); //Wyświetlenie tekstu
  73.       lcd.setCursor(0, 1);
  74.       lcd.print("Time: "+Output_Time(hour,minute,second)+"        ");
  75.  
  76.       if (stan_hour == 0 or stan_minute == 0 or stan_second ==0){
  77.         Inc_Dec_Time(stan_second,stan_minute,stan_hour);//INC/DEC czasu
  78.       }
  79.      
  80.     }
  81.    
  82.     if(counter%3 == 1){//Wyswietlanie max/min temperatury
  83.       lcd.setCursor(0,0);
  84.       lcd.print("Max temp:"+ String(max_temp)+(char)223+"C       ");
  85.       lcd.setCursor(0,1);
  86.       lcd.print("Min temp:" + String(min_temp)+(char)223+"C      ");
  87.      
  88.     }
  89.     if(counter%3 == 2){//Wyswietlanie aktualnej daty
  90.       int stan_year = digitalRead(A5); //Zmiana roku
  91.       int stan_month = digitalRead(A4); //Zmiana miesiaca
  92.       int stan_day = digitalRead(A3); //Zmiana dnia
  93.      
  94.      
  95.       lcd.setCursor(0,0);
  96.       lcd.print("Date: "+Output_Date(year,month,day)+"     "); //Wyświetlenie tekstu
  97.       lcd.setCursor(0,1);
  98.       lcd.print("Have a nice day!");
  99.      
  100.       if (stan_year == 0 or stan_month == 0 or stan_day ==0){
  101.         Inc_Dec_Date(stan_year,stan_month,stan_day);//INC/DEC daty
  102.       }
  103.     }
  104.   }
  105. }
  106.  
  107. void Min_Max(float liczba){
  108.   if(liczba > max_temp){
  109.     max_temp = liczba;
  110.   }
  111.   if(liczba < min_temp){
  112.     min_temp = liczba;
  113.   }
  114.  
  115. }
  116.  
  117. void Timer(){
  118.   second += 1;
  119.   if (second == 59)
  120.   {
  121.     second = 0;
  122.     minute += 1;
  123.   }
  124.   if (minute == 60)
  125.   {
  126.     minute = 0;
  127.     hour += 1;
  128.   }
  129.   if (hour == 24)
  130.   {
  131.     hour = 0;
  132.     day += 1;
  133.   }
  134.   if(hour == -1){
  135.     hour = 23;
  136.   }
  137.   if(minute == -1){
  138.     minute = 59;
  139.     hour -=1;
  140.   }
  141.    
  142.   delay(1000);
  143. }
  144.  
  145. String Output_Time(int H,int M,int S){
  146.   String output_T;
  147.   if (H<10){
  148.     output_T += String(0)+String(H)+":";
  149.   }
  150.   else{
  151.     output_T += String(H)+":";
  152.   }
  153.     if (M<10){
  154.     output_T += String(0)+String(M)+":";
  155.   }
  156.   else{
  157.     output_T += String(M)+":";
  158.   }
  159.  
  160.   if (S<10){
  161.     output_T += String(0)+String(S);
  162.   }
  163.   else{
  164.     output_T += String(S);
  165.   }
  166.  
  167.   return output_T;
  168. }
  169.  
  170.  
  171. String Output_Date(int Y,int M,int D){
  172.   String output_D = String(Y)+".";
  173.   if (M<10){
  174.     output_D += String(0)+String(M)+".";
  175.   }
  176.   else{
  177.     output_D += String(M)+".";
  178.   }
  179.  
  180.   if (D<10){
  181.     output_D += String(0)+String(D);
  182.   }
  183.   else{
  184.     output_D += String(D);
  185.   }
  186.   return output_D;
  187. }
  188.  
  189. void Inc_Dec_Time(int stan_second,int stan_minute,int stan_hour){
  190.    if (counter_ID%2 == 0){
  191.      if (stan_second == 0)
  192.       {
  193.         second += 1;
  194.       }
  195.      
  196.       if (stan_hour == 0)
  197.       {
  198.         hour += 1;
  199.       }
  200.      
  201.       if (stan_minute == 0)
  202.       {
  203.         minute += 1;
  204.       }
  205.     }
  206.     else{
  207.       if (stan_second == 0)
  208.       {
  209.         second -= 2;
  210.       }
  211.      
  212.       if (stan_hour == 0)
  213.       {
  214.         hour -= 1;
  215.       }
  216.      
  217.       if (stan_minute == 0)
  218.       {
  219.         minute -= 1;
  220.       }
  221.      
  222.     }
  223. }
  224.  
  225. void Inc_Dec_Date(int stan_year,int stan_month,int stan_day){
  226.    if (counter_ID%2 == 0){
  227.      if (stan_year == 0)
  228.       {
  229.         year += 1;
  230.       }
  231.      
  232.       if (stan_month == 0)
  233.       {
  234.         month += 1;
  235.       }
  236.      
  237.       if (stan_day == 0)
  238.       {
  239.         day += 1;
  240.       }
  241.       }
  242.     else{
  243.       if (stan_year == 0)
  244.       {
  245.         year -= 1;
  246.       }
  247.      
  248.       if (stan_month == 0)
  249.       {
  250.         month -= 1;
  251.       }
  252.      
  253.       if (stan_day == 0)
  254.       {
  255.         day -= 1;
  256.       }
  257.      
  258.     }
  259. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement