daily pastebin goal
19%
SHARE
TWEET

Untitled

a guest Dec 10th, 2018 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Visual Micro is in vMicro>General>Tutorial Mode
  2. //
  3. /*
  4.     Name:       lab1.ino
  5.     Created:    2018-11-26 12:18:25
  6.     Author:     DESKTOP-QAU1NK3\Michał
  7. */
  8.  
  9.  
  10.  
  11.  
  12. // Define User Types below here or use a .h file
  13. //
  14. #include <Wire.h>  
  15. #include <Adafruit_Sensor.h>
  16. #include <LiquidCrystal.h>
  17. #include <DHT_U.h>
  18. #include <LiquidCrystal_I2C.h>
  19. #include <Timers.h>
  20. #include <DHT.h>
  21. #include <Time.h>
  22. #include <TimeLib.h>
  23.  
  24.  
  25.  
  26.  
  27. // Define Function Prototypes that use User Types below here or use a .h file
  28. //
  29. #define DHT11_PIN 2
  30. #define DHTTYPE DHT11
  31.  
  32.  
  33. const int s1 = 5;
  34. const int s2 = 6;
  35. const int s3 = 7;
  36. const int greenLED = 8;
  37. const int redLED = 9;
  38. const int yellowLED = 10;
  39.  
  40.  
  41.  
  42. LiquidCrystal_I2C lcd(0x3F, 16, 2);
  43. DHT dht(DHT11_PIN, DHTTYPE);
  44. // Define Functions below here or use other .ino or cpp files
  45. //
  46.  
  47. int czasdokonca0;
  48. int liczniktemp;
  49. int licznikwil;
  50. int czasdokonca;
  51. int stan = 0;
  52.  
  53. // The setup() function runs once each time the micro-controller starts
  54. void setup()
  55. {
  56.     lcd.init();
  57.     lcd.backlight();
  58.  
  59.     pinMode(greenLED, OUTPUT);
  60.     pinMode(yellowLED, OUTPUT);
  61.     pinMode(redLED, OUTPUT);
  62.  
  63.     pinMode(s1, INPUT);
  64.     pinMode(s2, INPUT);
  65.     pinMode(s3, INPUT);
  66.  
  67.  
  68.     uzytkownicy();
  69.     dht.begin();
  70.     liczniktemp = 0;
  71.     licznikwil = 0;
  72. }
  73.  
  74. // Add the main program code into the continuous loop() function
  75. void loop()
  76. {
  77.     if (digitalRead(s1) == HIGH)
  78.     {
  79.         temperatura();
  80.         digitalWrite(greenLED, HIGH);
  81.     }
  82.  
  83.     if (digitalRead(s2) == HIGH)
  84.     {
  85.         wilgotnosc();
  86.         digitalWrite(yellowLED, HIGH);
  87.     }
  88.  
  89.     if (digitalRead(s3) == HIGH)
  90.     {
  91.         statystyki();
  92.         digitalWrite(redLED, HIGH);
  93.     }
  94.    
  95.     if (czasdokonca0 < now())
  96.     {
  97.         uzytkownicy();
  98.         czasdokonca = 0;
  99.     }
  100.     else
  101.     {
  102.         czasdokonca = czasdokonca0 - now();
  103.     }
  104.  
  105.     delay(3000);
  106. }
  107.  
  108. void uzytkownicy()
  109. {
  110.     //lcd.clear();
  111.     lcd.init();
  112.     lcd.backlight();
  113.     lcd.setCursor(0, 0);
  114.     lcd.print("USER1: Michal"); // Tekst który będzie wyświetlany w pierwszej linijce wyświetlacza
  115.     lcd.setCursor(0, 1);
  116.     lcd.print("USER2: Dawid");
  117.     digitalWrite(greenLED, LOW);
  118.     digitalWrite(yellowLED, LOW);
  119.     digitalWrite(redLED, LOW);
  120.  
  121. }
  122.  
  123. void temperatura()
  124. {
  125.     //lcd.clear();
  126.     lcd.setCursor(0, 0);
  127.     lcd.print("Temperatura");
  128.     lcd.setCursor(0, 1);
  129.     lcd.print(dht.readTemperature());
  130.     liczniktemp = liczniktemp + 1;
  131.     czasdokonca0 = now() + 5;
  132. }
  133.  
  134. void wilgotnosc()
  135. {
  136.     //lcd.clear();
  137.     lcd.setCursor(0, 0);
  138.     lcd.print("Wilgotnosc");
  139.     lcd.setCursor(0, 1);
  140.     lcd.print(dht.readHumidity());
  141.     licznikwil = licznikwil + 1;
  142.     czasdokonca0 = now() + 5;
  143. }
  144.  
  145. void statystyki()
  146. {
  147.     lcd.clear();
  148.     lcd.setCursor(0, 0);
  149.     lcd.print("ile temp:");
  150.     lcd.print(liczniktemp);
  151.     lcd.setCursor(0, 1);
  152.     lcd.print("Ile wilgot:");
  153.     lcd.print(licznikwil);
  154.     czasdokonca0 = now() + 5;
  155. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top