Compilation error: 'int LiquidCrystal_I2C::init()' is private within this context

Hi, I have a problem. I get an error as in the topic. How to prevent this? I have a library: LiquidCrystal by Arduino, Adafruit

CODE:

#include <Keypad.h>
#include <virtuabotixRTC.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>

#define I2C_ADDR 0x27 //LCD i2c stuff
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1 35
#define NOTE_D1  37
#define NOTE_DS1 39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1 46
#define NOTE_G1  49
#define NOTE_GS1 52
#define NOTE_A1  55
#define NOTE_AS1 58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2 69
#define NOTE_D2  73
#define NOTE_DS2 78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2 93
#define NOTE_G2  98
#define NOTE_GS2 104
#define NOTE_A2  110
#define NOTE_AS2 117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3 139
#define NOTE_D3  147
#define NOTE_DS3 156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3 208
#define NOTE_A3  220
#define NOTE_AS3 233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4 277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4 370
#define NOTE_G4  392
#define NOTE_GS4 415
#define NOTE_A4  440
#define NOTE_AS4 466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5 554
#define NOTE_D5  587
#define NOTE_DS5 622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5 740
#define NOTE_G5  784
#define NOTE_GS5 831
#define NOTE_A5  880
#define NOTE_AS5 932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6 1109
#define NOTE_D6  1175
#define NOTE_DS6 1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6 1480
#define NOTE_G6  1568
#define NOTE_GS6 1661
#define NOTE_A6  1760
#define NOTE_AS6 1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7 2217
#define NOTE_D7  2349
#define NOTE_DS7 2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7 2960
#define NOTE_G7  3136
#define NOTE_GS7 3322
#define NOTE_A7  3520
#define NOTE_AS7 3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8 4435
#define NOTE_D8  4699
#define NOTE_DS8 4978
#define REST      0

LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
virtuabotixRTC myRTC(2, 3, 4);
DHT dht(A0, DHT11);

const byte numRows= 4;
const byte numCols= 4; 

char keymap[numRows][numCols]= 
{
{'1', '2', '3', 'A'}, 
{'4', '5', '6', 'B'}, 
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};

byte rowPins[numRows] = {12,11,10,9};
byte colPins[numCols]= {8,7,6,5};

int i1,i2,i3,i4;
char c1,c2,c3,c4;
char keypressed,keypressedx;

int A_hour=NULL;
int A_minute=NULL;
int AlarmIsActive=NULL;
int buzzer = 13;
int tempo = 120;
int melody[] = {
  NOTE_A4,-4, NOTE_A4,-4, NOTE_A4,16, NOTE_A4,16, NOTE_A4,16, NOTE_A4,16, NOTE_F4,8, REST,8,
  NOTE_A4,-4, NOTE_A4,-4, NOTE_A4,16, NOTE_A4,16, NOTE_A4,16, NOTE_A4,16, NOTE_F4,8, REST,8,
  NOTE_A4,4, NOTE_A4,4, NOTE_A4,4, NOTE_F4,-8, NOTE_C5,16,

  NOTE_A4,4, NOTE_F4,-8, NOTE_C5,16, NOTE_A4,2,//4
  NOTE_E5,4, NOTE_E5,4, NOTE_E5,4, NOTE_F5,-8, NOTE_C5,16,
  NOTE_A4,4, NOTE_F4,-8, NOTE_C5,16, NOTE_A4,2,
  
  NOTE_A5,4, NOTE_A4,-8, NOTE_A4,16, NOTE_A5,4, NOTE_GS5,-8, NOTE_G5,16, //7 
  NOTE_DS5,16, NOTE_D5,16, NOTE_DS5,8, REST,8, NOTE_A4,8, NOTE_DS5,4, NOTE_D5,-8, NOTE_CS5,16,

  NOTE_C5,16, NOTE_B4,16, NOTE_C5,16, REST,8, NOTE_F4,8, NOTE_GS4,4, NOTE_F4,-8, NOTE_A4,-16,//9
  NOTE_C5,4, NOTE_A4,-8, NOTE_C5,16, NOTE_E5,2,

  NOTE_A5,4, NOTE_A4,-8, NOTE_A4,16, NOTE_A5,4, NOTE_GS5,-8, NOTE_G5,16, //7 
  NOTE_DS5,16, NOTE_D5,16, NOTE_DS5,8, REST,8, NOTE_A4,8, NOTE_DS5,4, NOTE_D5,-8, NOTE_CS5,16,

  NOTE_C5,16, NOTE_B4,16, NOTE_C5,16, REST,8, NOTE_F4,8, NOTE_GS4,4, NOTE_F4,-8, NOTE_A4,-16,//9
  NOTE_A4,4, NOTE_F4,-8, NOTE_C5,16, NOTE_A4,2,
  
};
int notes = sizeof(melody) / sizeof(melody[0]) / 2;
int wholenote = (60000 * 4) / tempo;
int divider = 0, noteDuration = 0;
int temp;
int humidity;

Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);

void setup() {
  pinMode(A0,OUTPUT);
  Temperatura();
  Serial.begin(9600);
  lcd.begin (16,2);
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.home ();
                                                   
}

void StarWars() {
  for (int thisNote = 0; thisNote < notes * 2; thisNote = thisNote + 2) {

    divider = melody[thisNote + 1];
    if (divider > 0) {
      noteDuration = (wholenote) / divider;
    } else if (divider < 0) {
      noteDuration = (wholenote) / abs(divider);
      noteDuration *= 1.5;
    }

    tone(buzzer, melody[thisNote], noteDuration*0.9);
    delay(noteDuration);    
    noTone(buzzer);
  }
}

void Temperatura() {
  dht.begin();
  lcd.init();
  lcd.backlight();
  }

void loop() {
  digitalWrite(A0,HIGH); 
  delay(2000);
  temp = dht.readTemperature();
  humidity = dht.readHumidity();
  lcd.setCursor(1,0);
  lcd.print("Temp:");
  lcd.print(temp);
  lcd.print("C");
  lcd.setCursor(1, 1);
  lcd.print("Wilg:");
  lcd.print(humidity);
  lcd.print("%");

  while(keypressed == NO_KEY){ 
  keypressed = myKeypad.getKey();
  lcd.clear(); //Here after clearing the LCD we take the time from the module and print it on the screen with usual LCD functions
  myRTC.updateTime();

  if(myRTC.hours==A_hour && myRTC.minutes==A_minute && AlarmIsActive==1 && myRTC.seconds >= 0 && myRTC.seconds <= 2){
    while(keypressedx == NO_KEY){
    StarWars();
    lcd.clear();
    lcd.print("Wstawaj!");
    keypressedx = myKeypad.getKey();
    }
  }
  keypressedx = NO_KEY;
  noTone(buzzer);
  lcd.setCursor(0,0);
  lcd.print(myRTC.dayofmonth);
  lcd.print("/");
  lcd.print(myRTC.month);
  lcd.print("/");
  lcd.print(myRTC.year);
  lcd.setCursor(0,1);
  lcd.print(myRTC.hours);
  lcd.print(":");
  lcd.print(myRTC.minutes);
  lcd.print(":");
  lcd.print(myRTC.seconds);
  delay(100);
  }
 

         if (keypressed == '*') //As we everytime check the key pressed we only proceed to setup if we press "*"
             {
              lcd.clear();
              lcd.print("     Setup");
             delay(1000);
              lcd.clear();
              lcd.print("Setup year");
                 char keypressed2 = myKeypad.waitForKey();  
                    if (keypressed2 != NO_KEY && keypressed2 !='*' && keypressed2 !='#' && keypressed2 !='A' && keypressed2 !='B' && keypressed2 !='C' && keypressed2 !='D' )
                      {
                       c1 = keypressed2;
                       lcd.setCursor(0, 1);
                       lcd.print(c1);
                       }
                 char      keypressed3 = myKeypad.waitForKey();
                    if (keypressed3 != NO_KEY && keypressed3 !='*' && keypressed3 !='#' && keypressed3 !='A' && keypressed3 !='B' && keypressed3 !='C' && keypressed3 !='D' )
                      {
                       c2 = keypressed3;
                       lcd.setCursor(1, 1);
                       lcd.print(c2);
                       }
                   char  keypressed4 = myKeypad.waitForKey();
                   if (keypressed4 != NO_KEY && keypressed4 !='*' && keypressed4 !='#' && keypressed4 !='A' && keypressed4 !='B' && keypressed4 !='C' && keypressed4 !='D' )
                      {
                       c3 = keypressed4;
                       lcd.setCursor(2, 1);
                       lcd.print(c3);
                       }
                   char   keypressed5 = myKeypad.waitForKey();
                   if (keypressed5 != NO_KEY && keypressed5 !='*' && keypressed5 !='#' && keypressed5 !='A' && keypressed5 !='B' && keypressed5 !='C' && keypressed5 !='D' )
                      {
                       c4 = keypressed5;
                       lcd.setCursor(3, 1);
                       lcd.print(c4);
                       }

                     i1=(c1-48)*1000;        //the keys pressed are stored into chars I convert them to int then i did some multiplication to get the code as an int of xxxx
                     i2=(c2-48)*100;
                     i3=(c3-48)*10;
                     i4=c4-48;
                     int N_year=i1+i2+i3+i4;
                   delay(500);
                     lcd.clear();
                     lcd.print("Setup month");

////////////////////////////////////////////////////////////////
                     char keypressed6 = myKeypad.waitForKey();  // here all programs are stopped until you enter the four digits then it gets compared to the code above
                    if (keypressed6 != NO_KEY && keypressed6 !='*' && keypressed6 !='#' && keypressed6 !='A' && keypressed6 !='B' && keypressed6 !='C' && keypressed6 !='D' )
                      {
                       c1 = keypressed6;
                       lcd.setCursor(0, 1);
                       lcd.print(c1);
                       }
                    char   keypressed7 = myKeypad.waitForKey();
                    if (keypressed7 != NO_KEY && keypressed7 !='*' && keypressed7 !='#' && keypressed7 !='A' && keypressed7 !='B' && keypressed7 !='C' && keypressed7 !='D' )
                      {
                       c2 = keypressed7;
                       lcd.setCursor(1, 1);
                       lcd.print(c2);
                       }


                     i1=(c1-48)*10;
                     i2=c2-48;
                    int N_month=i1+i2;
                     delay(500);

                     lcd.clear();
                     lcd.print("Setup Day");
                     
 ////////////////////////////////////////////////////////////////                    
                      char keypressed8 = myKeypad.waitForKey();  // here all programs are stopped until you enter the four digits then it gets compared to the code above
                    if (keypressed8 != NO_KEY && keypressed8 !='*' && keypressed8 !='#' && keypressed8 !='A' && keypressed8 !='B' && keypressed8 !='C' && keypressed8 !='D' )
                      {
                        c1 = keypressed8;
                       lcd.setCursor(0, 1);
                       lcd.print(c1);
                       }
                      char keypressed9 = myKeypad.waitForKey();
                    if (keypressed9 != NO_KEY && keypressed9 !='*' && keypressed9 !='#' && keypressed9 !='A' && keypressed9 !='B' && keypressed9 !='C' && keypressed9 !='D' )
                      {
                        c2 = keypressed9;
                       lcd.setCursor(1, 1);
                       lcd.print(c2);
                       }


                     i1=(c1-48)*10;
                     i2=c2-48;
                    int N_day=i1+i2;
                    delay(500);
                     lcd.clear();
                     lcd.print("Ustaw godzinę");
////////////////////////////////////////////////////////////////////////////////////:                     
                     char keypressed10 = myKeypad.waitForKey();  // here all programs are stopped until you enter the four digits then it gets compared to the code above
                    if (keypressed10 != NO_KEY && keypressed10 !='*' && keypressed10 !='#' && keypressed10 !='A' && keypressed10 !='B' && keypressed10 !='C' && keypressed10 !='D' )
                      {
                       c1 = keypressed10;
                       lcd.setCursor(0, 1);
                       lcd.print(c1);
                       }
                    char   keypressed11 = myKeypad.waitForKey();
                    if (keypressed11 != NO_KEY && keypressed11 !='*' && keypressed11 !='#' && keypressed11 !='A' && keypressed11 !='B' && keypressed11 !='C' && keypressed11 !='D' )
                      {
                        c2 = keypressed11;
                       lcd.setCursor(1, 1);
                       lcd.print(c2);
                       }


                     i1=(c1-48)*10;
                     i2=c2-48;
                    int N_hour=i1+i2;
                    delay(500);
                     lcd.clear();
                     lcd.print("Ustaw Minuty");
////////////////////////////////////////////////////////////////////////////////////:
                    char keypressed12 = myKeypad.waitForKey();  // here all programs are stopped until you enter the four digits then it gets compared to the code above
                    if (keypressed12 != NO_KEY && keypressed12 !='*' && keypressed12 !='#' && keypressed12 !='A' && keypressed12 !='B' && keypressed12 !='C' && keypressed12 !='D' )
                      {
                        c1 = keypressed12;
                       lcd.setCursor(0, 1);
                       lcd.print(c1);
                       }
                   char    keypressed13 = myKeypad.waitForKey();
                    if (keypressed13 != NO_KEY && keypressed13 !='*' && keypressed13 !='#' && keypressed13 !='A' && keypressed13 !='B' && keypressed13 !='C' && keypressed13 !='D' )
                      {
                        c2 = keypressed13;
                       lcd.setCursor(1, 1);
                       lcd.print(c2);
                       }


                     i1=(c1-48)*10;
                     i2=c2-48;
                    int N_minutes=i1+i2;
                    delay(500);
                     lcd.clear();

                    myRTC.setDS1302Time(22, N_minutes, N_hour, 1, N_day, N_month, N_year); //once we're done setting the date and time we transfer to values to the RTC module
                                                                                           //the 22 stands for seconds you can add a setup for it too if you want
                                                                                           //the 1 stands for day of the week, as long I don't show it on the screen I don't change it
                    keypressed=NO_KEY; //the "*" key is stored in "keypressed" so I remove that value from it otherwise it will get me in the setup again
              }
/////////////////////////////////////////Alarme setup/////////////////////////////////
              
             if (keypressed == 'A'){
              lcd.clear();
              lcd.print("  Alarm setup  ");
              delay(1000);
              lcd.clear();
              lcd.print("Set alarm hour");
               
               char keypressed14 = myKeypad.waitForKey();  // here all programs are stopped until you enter the four digits then it gets compared to the code above
                    if (keypressed14 != NO_KEY && keypressed14 !='*' && keypressed14 !='#' && keypressed14 !='A' && keypressed14 !='B' && keypressed14 !='C' && keypressed14 !='D' )
                      {
                       c1 = keypressed14;
                       lcd.setCursor(0, 1);
                       lcd.print(c1);
                       }
                    char   keypressed15 = myKeypad.waitForKey();
                    if (keypressed15 != NO_KEY && keypressed15 !='*' && keypressed15 !='#' && keypressed15 !='A' && keypressed15 !='B' && keypressed15 !='C' && keypressed15 !='D' )
                      {
                        c2 = keypressed15;
                       lcd.setCursor(1, 1);
                       lcd.print(c2);
                       }


                     i1=(c1-48)*10;
                     i2=c2-48;
                     A_hour=i1+i2;
                    delay(500);
                     lcd.clear();
                     lcd.print("Set alarm minutes");
                      char keypressed16 = myKeypad.waitForKey();  // here all programs are stopped until you enter the four digits then it gets compared to the code above
                    if (keypressed16 != NO_KEY && keypressed16 !='*' && keypressed16 !='#' && keypressed16 !='A' && keypressed16 !='B' && keypressed16 !='C' && keypressed16 !='D' )
                      {
                       c1 = keypressed16;
                       lcd.setCursor(0, 1);
                       lcd.print(c1);
                       }
                    char   keypressed17 = myKeypad.waitForKey();
                    if (keypressed17 != NO_KEY && keypressed17 !='*' && keypressed17 !='#' && keypressed17 !='A' && keypressed17 !='B' && keypressed17 !='C' && keypressed17 !='D' )
                      {
                        c2 = keypressed17;
                       lcd.setCursor(1, 1);
                       lcd.print(c2);
                       }


                     i1=(c1-48)*10;
                     i2=c2-48;
                     A_minute=i1+i2;
                    delay(500);
                     lcd.clear();
                      AlarmIsActive=1;
                      keypressed=NO_KEY;
             }
             if (keypressed == 'B')
             {
              lcd.clear();
              lcd.print("Alarm deactivated");
              AlarmIsActive=0;
              keypressed=NO_KEY;
              delay(500);
             }
             else {
              myRTC.updateTime();
              keypressed=NO_KEY;
             }
             

}

I would guess that you are using the syntax of code written for a LiquidCrystal_I2C library different from the one that is installed

Either replace the library with the one of the same name used by the originator of the code or check how your current library is used in its examples and change the code to match

when I change the library, an even worse error appears. Do you know how to modify the code? (I am new here)

The code will only work (if it ever did) with the same library as used by the author of the code.

Where did you get the code from ?

I combine 2 codes

1: Arduino Tutorial 25- Portable Temperature and Humidity Sensor with DHT11 (youtube.com)

2: Simple Arduino based Alarm Clock with DS1302 RTC – SURTR TECHNOLOGY

I suggest that you uninstall the LCD library that you are trying to use then view this video https://www.youtube.com/watch?v=mGLhEZRyHOQ

In the video the code author shows exactly which library he is using. Install it and get the LCD working as in the video before trying anything elae

ok, I will do that

it's working
should I change the library in the project?

I upload library from video, and this hapend

C:\Users\Kamil\Desktop\PROGRAMOWANIe.pl\dalej\dalej.ino: In function 'void setup()':
C:\Users\Kamil\Desktop\PROGRAMOWANIe.pl\dalej\dalej.ino:168:7: error: 'class LiquidCrystal_I2C' has no member named 'setBacklightPin'; did you mean 'setBacklight'?
   lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
       ^~~~~~~~~~~~~~~
       setBacklight
C:\Users\Kamil\Desktop\PROGRAMOWANIe.pl\dalej\dalej.ino:168:37: error: 'POSITIVE' was not declared in this scope
   lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
                                     ^~~~~~~~
Znaleziono wiele bibliotek w "LiquidCrystal_I2C.h"
  Wykorzystane: D:\Users\Kamil\Documents\Arduino\libraries\LiquidCrystal_I2C
  Niewykorzystane: D:\Users\Kamil\Documents\Arduino\libraries\Newliquidcrystal_1.3.5
exit status 1

Compilation error: 'class LiquidCrystal_I2C' has no member named 'setBacklightPin'; did you mean 'setBacklight'?

Did you try the code associated with the video ?

i'v got it

Does it work ?

no, i will try other code for DSH11

I just loaded another program, but the display does not display it. Any idea why? (after verifying there is no error)

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>

#define DHTPIN A0
#define DHTTYPE DHT11

LiquidCrystal_I2C lcd(0x27, 16, 2); // Adres I2C 0x27 (dla ekranu DIYables), 16 kolumn i 2 wiersze
DHT dht(DHTPIN, DHTTYPE);

void setup() {
    pinMode(A0,OUTPUT);
    Wire.begin(); // Inicjalizacja komunikacji I2C
    dht.begin(); // Inicjalizacja czujnika
    lcd.backlight(); // Włączenie podświetlenia
}

void loop() {
    digitalWrite(A0,HIGH);
    delay(2000); // Poczekaj kilka sekund między odczytami
    float humi = dht.readHumidity(); // Odczyt wilgotności
    float tempC = dht.readTemperature(); // Odczyt temperatury

    lcd.clear(); // Wyczyść ekran

    if (isnan(humi) || isnan(tempC)) {
        lcd.setCursor(0, 0);
        lcd.print("Błąd odczytu");
    } else {
        lcd.setCursor(0, 0);
        lcd.print("Temp: ");
        lcd.print(tempC);
        lcd.print((char)223); // Symbol stopni
        lcd.print("C");

        lcd.setCursor(0, 1);
        lcd.print("Wilg: ");
        lcd.print(humi);
        lcd.print("%");
    }
}

I have closed your other topic about the LCD display so that replies are all in one place

Why are you setting pin A0 HIGH ?

I want to change the pin from analog to digital

You don't need to do that. Let the DHT library deal with the pin

still nothing

Are you seeing anything on the LCD ?

The code works for me although it has a bug in the output section cursor positioning and I can't use pin A0 because of how my test system is arranged. I am using pin 2 instead which should make no difference

My guess is that the sensor is not returning a value. How is wired and is it a bare sensor with 4 pins or is it on a small board with only 3 pins ?

on the board with 3 pins
I managed to upload the code to Arduino, it displays the values but they do not change. There is actually something going on here

#include <Keypad.h> //Libraries needed
#include <virtuabotixRTC.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <DHT.h>

#define DHTPIN A0
#define DHTTYPE DHT11
#define I2C_ADDR 0x27 //LCD i2c stuff
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
DHT dht(DHTPIN, DHTTYPE);


virtuabotixRTC myRTC(2, 3, 4); //Wiring of the RTC (CLK,DAT,RST)
                               //If you change the wiring change the pins here also


const byte numRows= 4; //number of rows on the keypad
const byte numCols= 4; //number of columns on the keypad

//keymap defines the key pressed according to the row and columns just as appears on the keypad
char keymap[numRows][numCols]= 
{
{'1', '2', '3', 'A'}, 
{'4', '5', '6', 'B'}, 
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};


byte rowPins[numRows] = {12,11,10,9}; //Rows 0 to 3 //if you modify your pins you should modify this too
byte colPins[numCols]= {8,7,6,5}; //Columns 0 to 3

int i1,i2,i3,i4;
char c1,c2,c3,c4;
char keypressed,keypressedx;

int A_hour=NULL;
int A_minute=NULL;
int AlarmIsActive=NULL;

int buzzer = 13;


Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);


void setup() {
  Serial.begin(9600);
  lcd.begin (16,2); //Initialize the LCD
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.home ();
  Wire.begin(); // Inicjalizacja komunikacji I2C
  dht.begin(); // Inicjalizacja czujnika                                     
}

void loop() {
  delay(2000); // Poczekaj kilka sekund między odczytami
    float humi = dht.readHumidity(); // Odczyt wilgotności
    float tempC = dht.readTemperature(); // Odczyt temperatury
  while(keypressed == NO_KEY){ //As long as no key is pressed we keep showing the date and time, I'm obliged to clear the screen everytime so the numbers don't get confused
                               //And I should add that little delay so the screen shows correctly otherwise it didn't work for me
  keypressed = myKeypad.getKey();
  lcd.clear(); //Here after clearing the LCD we take the time from the module and print it on the screen with usual LCD functions
  myRTC.updateTime();

  if(myRTC.hours==A_hour && myRTC.minutes==A_minute && AlarmIsActive==1 && myRTC.seconds >= 0 && myRTC.seconds <= 2){
    while(keypressedx == NO_KEY){
    tone(buzzer, 1000); //You can modify the tone or make your own sound
    delay(100);
    tone(buzzer, 2000);
    delay(100);
    lcd.clear();
    lcd.print("Get up !!!"); //Message to show when the alarm is ringing
    keypressedx = myKeypad.getKey();
    }
  }
  keypressedx = NO_KEY;
  noTone(buzzer);
  lcd.setCursor(0,0);
  lcd.print(myRTC.dayofmonth);
  lcd.print("/");
  lcd.print(myRTC.month);
  lcd.print("/");
  lcd.print(myRTC.year);
  lcd.print("T:");
  lcd.print(tempC);
  lcd.print((char)223); // Symbol stopni
  lcd.print("C");
  lcd.setCursor(0,1);
  lcd.print(myRTC.hours);
  lcd.print(":");
  lcd.print(myRTC.minutes);
  lcd.print(":");
  lcd.print(myRTC.seconds);
  lcd.print(" W:");
  lcd.print(humi);
  lcd.print("%");
  delay(100);
  }
 

         if (keypressed == '*') //As we everytime check the key pressed we only proceed to setup if we press "*"
             {
              lcd.clear();
              lcd.print("     Setup");
             delay(1000);
              lcd.clear();
              lcd.print("Setup year");
              //So you can understand how this works, first it shows us "setup" then it prints "setup year" and now you can write your year normally (2-0-1-8)
              //It automatically passes to setting up the month...until it's finished
              //The keys from keypad are all considered chars (c) so we should convert them to int that's what I did then we store them (i)
              //We do some math and we get the year, month... as int so we can inject them to the RTC otherwise it will not be compiled
              //Months like April you should write 04, 03 for March... otherwise it will not pass to the next parameter
              //The RTC virtuabotix library is already set to not accept strange time and dates (45/17/1990) (58:90:70), and yes old dates are considered as errors
             char keypressed2 = myKeypad.waitForKey();  
                    if (keypressed2 != NO_KEY && keypressed2 !='*' && keypressed2 !='#' && keypressed2 !='A' && keypressed2 !='B' && keypressed2 !='C' && keypressed2 !='D' )
                      {
                       c1 = keypressed2;
                       lcd.setCursor(0, 1);
                       lcd.print(c1);
                       }
                 char      keypressed3 = myKeypad.waitForKey();
                    if (keypressed3 != NO_KEY && keypressed3 !='*' && keypressed3 !='#' && keypressed3 !='A' && keypressed3 !='B' && keypressed3 !='C' && keypressed3 !='D' )
                      {
                       c2 = keypressed3;
                       lcd.setCursor(1, 1);
                       lcd.print(c2);
                       }
                   char  keypressed4 = myKeypad.waitForKey();
                   if (keypressed4 != NO_KEY && keypressed4 !='*' && keypressed4 !='#' && keypressed4 !='A' && keypressed4 !='B' && keypressed4 !='C' && keypressed4 !='D' )
                      {
                       c3 = keypressed4;
                       lcd.setCursor(2, 1);
                       lcd.print(c3);
                       }
                   char   keypressed5 = myKeypad.waitForKey();
                   if (keypressed5 != NO_KEY && keypressed5 !='*' && keypressed5 !='#' && keypressed5 !='A' && keypressed5 !='B' && keypressed5 !='C' && keypressed5 !='D' )
                      {
                       c4 = keypressed5;
                       lcd.setCursor(3, 1);
                       lcd.print(c4);
                       }

                     i1=(c1-48)*1000;        //the keys pressed are stored into chars I convert them to int then i did some multiplication to get the code as an int of xxxx
                     i2=(c2-48)*100;
                     i3=(c3-48)*10;
                     i4=c4-48;
                     int N_year=i1+i2+i3+i4;
                   delay(500);
                     lcd.clear();
                     lcd.print("Setup month");

////////////////////////////////////////////////////////////////
                     char keypressed6 = myKeypad.waitForKey();  // here all programs are stopped until you enter the four digits then it gets compared to the code above
                    if (keypressed6 != NO_KEY && keypressed6 !='*' && keypressed6 !='#' && keypressed6 !='A' && keypressed6 !='B' && keypressed6 !='C' && keypressed6 !='D' )
                      {
                       c1 = keypressed6;
                       lcd.setCursor(0, 1);
                       lcd.print(c1);
                       }
                    char   keypressed7 = myKeypad.waitForKey();
                    if (keypressed7 != NO_KEY && keypressed7 !='*' && keypressed7 !='#' && keypressed7 !='A' && keypressed7 !='B' && keypressed7 !='C' && keypressed7 !='D' )
                      {
                       c2 = keypressed7;
                       lcd.setCursor(1, 1);
                       lcd.print(c2);
                       }


                     i1=(c1-48)*10;
                     i2=c2-48;
                    int N_month=i1+i2;
                     delay(500);

                     lcd.clear();
                     lcd.print("Setup Day");
                     
 ////////////////////////////////////////////////////////////////                    
                      char keypressed8 = myKeypad.waitForKey();  // here all programs are stopped until you enter the four digits then it gets compared to the code above
                    if (keypressed8 != NO_KEY && keypressed8 !='*' && keypressed8 !='#' && keypressed8 !='A' && keypressed8 !='B' && keypressed8 !='C' && keypressed8 !='D' )
                      {
                        c1 = keypressed8;
                       lcd.setCursor(0, 1);
                       lcd.print(c1);
                       }
                      char keypressed9 = myKeypad.waitForKey();
                    if (keypressed9 != NO_KEY && keypressed9 !='*' && keypressed9 !='#' && keypressed9 !='A' && keypressed9 !='B' && keypressed9 !='C' && keypressed9 !='D' )
                      {
                        c2 = keypressed9;
                       lcd.setCursor(1, 1);
                       lcd.print(c2);
                       }


                     i1=(c1-48)*10;
                     i2=c2-48;
                    int N_day=i1+i2;
                    delay(500);
                     lcd.clear();
                     lcd.print("Setup hour");
////////////////////////////////////////////////////////////////////////////////////:                     
                     char keypressed10 = myKeypad.waitForKey();  // here all programs are stopped until you enter the four digits then it gets compared to the code above
                    if (keypressed10 != NO_KEY && keypressed10 !='*' && keypressed10 !='#' && keypressed10 !='A' && keypressed10 !='B' && keypressed10 !='C' && keypressed10 !='D' )
                      {
                       c1 = keypressed10;
                       lcd.setCursor(0, 1);
                       lcd.print(c1);
                       }
                    char   keypressed11 = myKeypad.waitForKey();
                    if (keypressed11 != NO_KEY && keypressed11 !='*' && keypressed11 !='#' && keypressed11 !='A' && keypressed11 !='B' && keypressed11 !='C' && keypressed11 !='D' )
                      {
                        c2 = keypressed11;
                       lcd.setCursor(1, 1);
                       lcd.print(c2);
                       }


                     i1=(c1-48)*10;
                     i2=c2-48;
                    int N_hour=i1+i2;
                    delay(500);
                     lcd.clear();
                     lcd.print("Setup minutes");
////////////////////////////////////////////////////////////////////////////////////:
                    char keypressed12 = myKeypad.waitForKey();  // here all programs are stopped until you enter the four digits then it gets compared to the code above
                    if (keypressed12 != NO_KEY && keypressed12 !='*' && keypressed12 !='#' && keypressed12 !='A' && keypressed12 !='B' && keypressed12 !='C' && keypressed12 !='D' )
                      {
                        c1 = keypressed12;
                       lcd.setCursor(0, 1);
                       lcd.print(c1);
                       }
                   char    keypressed13 = myKeypad.waitForKey();
                    if (keypressed13 != NO_KEY && keypressed13 !='*' && keypressed13 !='#' && keypressed13 !='A' && keypressed13 !='B' && keypressed13 !='C' && keypressed13 !='D' )
                      {
                        c2 = keypressed13;
                       lcd.setCursor(1, 1);
                       lcd.print(c2);
                       }


                     i1=(c1-48)*10;
                     i2=c2-48;
                    int N_minutes=i1+i2;
                    delay(500);
                     lcd.clear();

                    myRTC.setDS1302Time(22, N_minutes, N_hour, 1, N_day, N_month, N_year); //once we're done setting the date and time we transfer to values to the RTC module
                                                                                           //the 22 stands for seconds you can add a setup for it too if you want
                                                                                           //the 1 stands for day of the week, as long I don't show it on the screen I don't change it
                    keypressed=NO_KEY; //the "*" key is stored in "keypressed" so I remove that value from it otherwise it will get me in the setup again
              }
/////////////////////////////////////////Alarme setup/////////////////////////////////
              
             if (keypressed == 'A'){
              lcd.clear();
              lcd.print("  Alarm setup  ");
              delay(1000);
              lcd.clear();
              lcd.print("Set alarm hour");
               
               char keypressed14 = myKeypad.waitForKey();  // here all programs are stopped until you enter the four digits then it gets compared to the code above
                    if (keypressed14 != NO_KEY && keypressed14 !='*' && keypressed14 !='#' && keypressed14 !='A' && keypressed14 !='B' && keypressed14 !='C' && keypressed14 !='D' )
                      {
                       c1 = keypressed14;
                       lcd.setCursor(0, 1);
                       lcd.print(c1);
                       }
                    char   keypressed15 = myKeypad.waitForKey();
                    if (keypressed15 != NO_KEY && keypressed15 !='*' && keypressed15 !='#' && keypressed15 !='A' && keypressed15 !='B' && keypressed15 !='C' && keypressed15 !='D' )
                      {
                        c2 = keypressed15;
                       lcd.setCursor(1, 1);
                       lcd.print(c2);
                       }


                     i1=(c1-48)*10;
                     i2=c2-48;
                     A_hour=i1+i2;
                    delay(500);
                     lcd.clear();
                     lcd.print("Set alarm minutes");
                      char keypressed16 = myKeypad.waitForKey();  // here all programs are stopped until you enter the four digits then it gets compared to the code above
                    if (keypressed16 != NO_KEY && keypressed16 !='*' && keypressed16 !='#' && keypressed16 !='A' && keypressed16 !='B' && keypressed16 !='C' && keypressed16 !='D' )
                      {
                       c1 = keypressed16;
                       lcd.setCursor(0, 1);
                       lcd.print(c1);
                       }
                    char   keypressed17 = myKeypad.waitForKey();
                    if (keypressed17 != NO_KEY && keypressed17 !='*' && keypressed17 !='#' && keypressed17 !='A' && keypressed17 !='B' && keypressed17 !='C' && keypressed17 !='D' )
                      {
                        c2 = keypressed17;
                       lcd.setCursor(1, 1);
                       lcd.print(c2);
                       }


                     i1=(c1-48)*10;
                     i2=c2-48;
                     A_minute=i1+i2;
                    delay(500);
                     lcd.clear();
                      AlarmIsActive=1;
                      keypressed=NO_KEY;
             }
             if (keypressed == 'B')
             {
              lcd.clear();
              lcd.print("Alarm deactivated");
              AlarmIsActive=0;
              keypressed=NO_KEY;
              delay(500);
             }
             else {
              myRTC.updateTime();
              keypressed=NO_KEY;
             }
             

}