Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- #include <Wire.h> //Biblioteka od termometru
- LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
- void setup() {
- #define LM35 A0 //
- lcd.begin(16, 2);
- pinMode(A1, OUTPUT); //Buzzer aktywny
- pinMode(A3, INPUT_PULLUP);//Przycisk do zmiany sekundy(tylko ++)
- pinMode(A4, INPUT_PULLUP);//Przycisk do zmiany minuty(tylko ++)
- pinMode(A5, INPUT_PULLUP);//Przycisk do zmiany godziny(tylko ++)
- pinMode(8,INPUT_PULLUP);//Przycisk do zmiany menu
- pinMode(9,OUTPUT); //Zielony LED
- pinMode(10,OUTPUT); //Czerwony LED
- pinMode(13,INPUT_PULLUP); // Przycisk symulujacy wykrycie dymu
- }
- int hour = 23; //Godzina
- int minute = 59; //Minuta
- int second = 40; //Sekunda
- int year = 2019; //Rok
- int month = 12; //Miesiac
- int day = 22; //Dzien
- float min_temp = 10000.0;
- float max_temp = 0.0;
- int counter = 0;//Pomocniczna zmienna uzywana do wyswietlana odpowiedniego menu
- int counter_ID = 0;//Pomocnicza zmienna uzywana do zmiany INC/DEC
- void loop() {
- float temperatura = (analogRead(LM35)/10.00);//Odczyt temperatury
- Min_Max(temperatura);//Wyznaczenie MAX/MIN temperatury
- Timer();//Zegar
- if(digitalRead(13) == LOW){ //Jesli wykryjemy dym
- while(digitalRead(13) == LOW){//Gdy trzymamy prrzycisk wykonuje sie tylko ten blok
- Timer();//Zegar
- tone(A1, 1000);
- digitalWrite(9,0);//Zgaszenie zielonej diody
- digitalWrite(10,1);//Zaswiecenie czerwonej diody
- digitalWrite(A1, LOW);
- delay(10);
- digitalWrite(A1, HIGH);
- delay(10);
- lcd.setCursor(0, 0);
- lcd.print("UWAGA UWAGA ");
- lcd.setCursor(0, 1);
- lcd.print("WYKRYTO ZAGROZENIE ");
- }
- counter_ID++;//Zmiana DEC/INC
- }
- else{
- noTone(A1);//Wylaczenie buzzera
- digitalWrite(9,1);//Zgaszenie czerwonej diody
- digitalWrite(10,0);//Zapalenie zielonej diody
- int stan = digitalRead(8);//Stan przycisku od zmiany menu
- if (stan == LOW){
- while(digitalRead(8) == LOW){ //Jesli przytrzymamy przycisk to i tak zmieni on menu o jedna pozycje
- Timer();//Zegar
- }
- counter++;//Inkrementacja menu
- }
- if(counter%3 == 0){//Wyswietlenie aktualnej temperatury i czasu
- int stan_hour = digitalRead(A5); //Zmiana godziny
- int stan_minute = digitalRead(A4); //Zmiana minut
- int stan_second = digitalRead(A3); //Zmiana minut
- lcd.setCursor(0, 0); //Ustawienie kursora
- lcd.print("Temp: "+ String(temperatura)+(char)223+"C "); //Wyświetlenie tekstu
- lcd.setCursor(0, 1);
- lcd.print("Time: "+Output_Time(hour,minute,second)+" ");
- if (stan_hour == 0 or stan_minute == 0 or stan_second ==0){
- Inc_Dec_Time(stan_second,stan_minute,stan_hour);//INC/DEC czasu
- }
- }
- if(counter%3 == 1){//Wyswietlanie max/min temperatury
- lcd.setCursor(0,0);
- lcd.print("Max temp:"+ String(max_temp)+(char)223+"C ");
- lcd.setCursor(0,1);
- lcd.print("Min temp:" + String(min_temp)+(char)223+"C ");
- }
- if(counter%3 == 2){//Wyswietlanie aktualnej daty
- int stan_year = digitalRead(A5); //Zmiana roku
- int stan_month = digitalRead(A4); //Zmiana miesiaca
- int stan_day = digitalRead(A3); //Zmiana dnia
- lcd.setCursor(0,0);
- lcd.print("Date: "+Output_Date(year,month,day)+" "); //Wyświetlenie tekstu
- lcd.setCursor(0,1);
- lcd.print("Have a nice day!");
- if (stan_year == 0 or stan_month == 0 or stan_day ==0){
- Inc_Dec_Date(stan_year,stan_month,stan_day);//INC/DEC daty
- }
- }
- }
- }
- void Min_Max(float liczba){
- if(liczba > max_temp){
- max_temp = liczba;
- }
- if(liczba < min_temp){
- min_temp = liczba;
- }
- }
- void Timer(){
- second += 1;
- if (second == 59)
- {
- second = 0;
- minute += 1;
- }
- if (minute == 60)
- {
- minute = 0;
- hour += 1;
- }
- if (hour == 24)
- {
- hour = 0;
- day += 1;
- }
- if(hour == -1){
- hour = 23;
- }
- if(minute == -1){
- minute = 59;
- hour -=1;
- }
- delay(1000);
- }
- String Output_Time(int H,int M,int S){
- String output_T;
- if (H<10){
- output_T += String(0)+String(H)+":";
- }
- else{
- output_T += String(H)+":";
- }
- if (M<10){
- output_T += String(0)+String(M)+":";
- }
- else{
- output_T += String(M)+":";
- }
- if (S<10){
- output_T += String(0)+String(S);
- }
- else{
- output_T += String(S);
- }
- return output_T;
- }
- String Output_Date(int Y,int M,int D){
- String output_D = String(Y)+".";
- if (M<10){
- output_D += String(0)+String(M)+".";
- }
- else{
- output_D += String(M)+".";
- }
- if (D<10){
- output_D += String(0)+String(D);
- }
- else{
- output_D += String(D);
- }
- return output_D;
- }
- void Inc_Dec_Time(int stan_second,int stan_minute,int stan_hour){
- if (counter_ID%2 == 0){
- if (stan_second == 0)
- {
- second += 1;
- }
- if (stan_hour == 0)
- {
- hour += 1;
- }
- if (stan_minute == 0)
- {
- minute += 1;
- }
- }
- else{
- if (stan_second == 0)
- {
- second -= 2;
- }
- if (stan_hour == 0)
- {
- hour -= 1;
- }
- if (stan_minute == 0)
- {
- minute -= 1;
- }
- }
- }
- void Inc_Dec_Date(int stan_year,int stan_month,int stan_day){
- if (counter_ID%2 == 0){
- if (stan_year == 0)
- {
- year += 1;
- }
- if (stan_month == 0)
- {
- month += 1;
- }
- if (stan_day == 0)
- {
- day += 1;
- }
- }
- else{
- if (stan_year == 0)
- {
- year -= 1;
- }
- if (stan_month == 0)
- {
- month -= 1;
- }
- if (stan_day == 0)
- {
- day -= 1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement