Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Visual Micro is in vMicro>General>Tutorial Mode
- //
- /*
- Name: lab1.ino
- Created: 2018-11-26 12:18:25
- Author: DESKTOP-QAU1NK3\Michał
- */
- // Define User Types below here or use a .h file
- //
- #include <Wire.h>
- #include <Adafruit_Sensor.h>
- #include <LiquidCrystal.h>
- #include <DHT_U.h>
- #include <LiquidCrystal_I2C.h>
- #include <Timers.h>
- #include <DHT.h>
- #include <Time.h>
- #include <TimeLib.h>
- // Define Function Prototypes that use User Types below here or use a .h file
- //
- #define DHT11_PIN 2
- #define DHTTYPE DHT11
- const int s1 = 5;
- const int s2 = 6;
- const int s3 = 7;
- const int greenLED = 8;
- const int redLED = 9;
- const int yellowLED = 10;
- LiquidCrystal_I2C lcd(0x3F, 16, 2);
- DHT dht(DHT11_PIN, DHTTYPE);
- // Define Functions below here or use other .ino or cpp files
- //
- int czasdokonca0;
- int liczniktemp;
- int licznikwil;
- int czasdokonca;
- int stan = 0;
- // The setup() function runs once each time the micro-controller starts
- void setup()
- {
- lcd.init();
- lcd.backlight();
- pinMode(greenLED, OUTPUT);
- pinMode(yellowLED, OUTPUT);
- pinMode(redLED, OUTPUT);
- pinMode(s1, INPUT);
- pinMode(s2, INPUT);
- pinMode(s3, INPUT);
- uzytkownicy();
- dht.begin();
- liczniktemp = 0;
- licznikwil = 0;
- }
- // Add the main program code into the continuous loop() function
- void loop()
- {
- if (digitalRead(s1) == HIGH)
- {
- temperatura();
- digitalWrite(greenLED, HIGH);
- }
- if (digitalRead(s2) == HIGH)
- {
- wilgotnosc();
- digitalWrite(yellowLED, HIGH);
- }
- if (digitalRead(s3) == HIGH)
- {
- statystyki();
- digitalWrite(redLED, HIGH);
- }
- if (czasdokonca0 < now())
- {
- uzytkownicy();
- czasdokonca = 0;
- }
- else
- {
- czasdokonca = czasdokonca0 - now();
- }
- delay(3000);
- }
- void uzytkownicy()
- {
- //lcd.clear();
- lcd.init();
- lcd.backlight();
- lcd.setCursor(0, 0);
- lcd.print("USER1: Michal"); // Tekst który będzie wyświetlany w pierwszej linijce wyświetlacza
- lcd.setCursor(0, 1);
- lcd.print("USER2: Dawid");
- digitalWrite(greenLED, LOW);
- digitalWrite(yellowLED, LOW);
- digitalWrite(redLED, LOW);
- }
- void temperatura()
- {
- //lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Temperatura");
- lcd.setCursor(0, 1);
- lcd.print(dht.readTemperature());
- liczniktemp = liczniktemp + 1;
- czasdokonca0 = now() + 5;
- }
- void wilgotnosc()
- {
- //lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Wilgotnosc");
- lcd.setCursor(0, 1);
- lcd.print(dht.readHumidity());
- licznikwil = licznikwil + 1;
- czasdokonca0 = now() + 5;
- }
- void statystyki()
- {
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("ile temp:");
- lcd.print(liczniktemp);
- lcd.setCursor(0, 1);
- lcd.print("Ile wilgot:");
- lcd.print(licznikwil);
- czasdokonca0 = now() + 5;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement