Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //*************************** BIBLIOTEKI ***********************************
- #include <Wire.h> // standardowa biblioteka Arduino
- #include <LiquidCrystal_I2C.h> // dolaczenie pobranej biblioteki I2C dla LCD
- #include <DS3231.h>
- #include <DHT.h>
- //*************************** KONIEC BIBLIOTEK *****************************
- //*************************** STAŁE !!! ************************************
- //DHT
- #define DHTTYPE DHT22
- #define DHTPIN 2
- //-DHT
- //Pilot
- #define D0 3
- #define D1 4
- #define D2 5
- #define D3 6
- //-Pilot
- //Czujnik zbliżenia
- #define PIRPIN 8
- //-Czujnik zbliżenia
- //*************************** KONIEC STAŁYCH *******************************
- //*************************** ZMIENNE **************************************
- int a, b, c, d, stan, czysc;
- //*************************** KONIEC ZMIENNYCH *****************************
- //*************************** DEFINICJE OBIEKTÓW ***************************
- //DHT
- DHT dht(DHTPIN, DHTTYPE); //DHT22
- //-DHT
- //RTC
- DS3231 clock;
- RTCDateTime dt;
- //-RTC
- //LCD I2C
- LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
- //-LCD I2C
- //*************************** KONIEC OBIEKTÓW ******************************
- void setup() {
- pinMode(PIRPIN, INPUT);
- pinMode(D0, INPUT);
- pinMode(D1, INPUT);
- pinMode(D2, INPUT);
- pinMode(D3, INPUT);
- Serial.begin(9600);
- Serial.println("DHT22 test!");
- Serial.println("PIR Test!");
- lcd.begin(20, 4); // Inicjalizacja LCD 2x16
- dht.begin();
- lcd.backlight();
- lcd.setCursor(0, 0);
- }
- void loop() {
- float *Temperatura = Wczytaj_Temperature();
- dt = clock.getDateTime();
- a = digitalRead(D0);
- b = digitalRead(D1);
- c = digitalRead(D2);
- d = digitalRead(D3);
- if (a == HIGH) {
- stan = 1;
- czysc = 1;
- };
- if (b == HIGH) {
- stan = 2;
- czysc = 1;
- }
- Ustawienia_Wyswietlacza(stan, czysc, Temperatura);
- czysc = 0;
- //ZWALNIANIE PAMIĘCI ! BARDZO WAŻNE !!
- delete [] Temperatura;
- }
- //*************************** FUNKCJE **************************************
- float *Wczytaj_Temperature(void) {
- float *temp = new float[2];
- temp[0] = dht.readTemperature();
- temp[1] = dht.readHumidity();
- return temp;
- }
- void Ustawienia_Wyswietlacza(int Stan, int Czysc_Ekran, float *Dane) {
- if (Czysc_Ekran == 1) {
- lcd.clear();
- }
- switch (Stan) {
- case 1:
- lcd.setCursor(0, 0);
- lcd.print("Temperatura: ");
- lcd.print(Dane[0]);
- lcd.setCursor(0, 1);
- lcd.print("Wilgotnosc: ");
- lcd.print(Dane[1]);
- break;
- case 2:
- lcd.setCursor(0, 0);
- lcd.print("Data i czas");
- lcd.setCursor(0, 1);
- lcd.print(clock.dateFormat("d-m-Y H:i:s", dt));
- break;
- default:
- lcd.setCursor(0, 0);
- lcd.print("DEFAULT");
- }
- }
- //*************************** KONIEC FUNKCJI *******************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement