Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <RTClib.h>
- char buffer1[20];
- char buffer2[20];
- const int setpin = 13;
- boolean statepin = 0;
- RTC_DS1307 RTC;
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd(0x27,20,4);
- #include "DHT.h"
- #define DHTPIN 2
- #define DHTTYPE DHT22
- DHT dht(DHTPIN, DHTTYPE);
- float h = dht.readHumidity();
- // Read temperature as Celsius (the default)
- float t = dht.readTemperature();
- float hic = dht.computeHeatIndex(t, h, false);
- int pulsSU = 3;
- int pulsGIU= 4;
- int pulsSET =5;
- int pulsMENU= 6;
- int Ton;
- int Toff;
- int EXIT;
- int umidita;
- int temperatura;
- int minuti;
- int ore;
- int step_funzione=0;
- void setup() {
- Serial.begin(9600);
- Wire.begin();
- RTC.begin();
- lcd.init();
- lcd.backlight();
- dht.begin();
- pinMode (pulsSU,INPUT);
- pinMode (pulsGIU,INPUT);
- pinMode (pulsSET,INPUT);
- pinMode (pulsMENU,INPUT);
- if (! RTC.isrunning()) {
- RTC.adjust(DateTime(__DATE__, __TIME__));
- }
- }
- void loop() {
- statepin = digitalRead (setpin);
- if (statepin == LOW)
- {
- RTC.adjust(DateTime(__DATE__, __TIME__));
- }
- DateTime now = RTC.now();
- sprintf(buffer1, "%02d:%02d:%02d", now.hour(), now.minute(), now.second());
- //lcd.setCursor(0,0);
- //lcd.print( buffer1 );
- sprintf(buffer2, "%02d/%02d/%d", now.day(), now.month(), now.year());
- //lcd.setCursor(0,1);
- //lcd.print( buffer2 );
- switch (step_funzione) {
- case 0: // STATO INIZIALE
- INIZIO();
- break;
- case 1:
- set_timeON();
- break;
- case 2:
- // set_timeOFF();
- break;
- // case 3:
- // break;
- }
- }
- void INIZIO (){
- t = dht.readTemperature();
- h = dht.readHumidity();
- lcd.setCursor(6,0);
- lcd.print(buffer1);
- lcd.setCursor(0,1);
- lcd.print("TEMP: C.");
- lcd.setCursor(6,1);
- lcd.print(t);
- lcd.setCursor(0,2);
- lcd.print("UMIDITA': %");
- lcd.setCursor(9,2);
- lcd.print(h);
- if(digitalRead(pulsMENU) == HIGH){
- delay(1000);
- //parte statica
- lcd.clear();
- lcd.setCursor(2, 0);
- lcd.print("SET TIME LIGHT-ON");
- step_funzione=1;
- }
- }
- void set_timeON(){
- if(digitalRead(pulsSU) == HIGH) {
- delay(1);
- minuti++;
- }
- if (minuti>59){
- minuti=0;
- ore++;}
- if (ore>23){
- ore=0;}
- lcd.setCursor(7, 2);
- if (ore < 10) lcd.print("0"); // SE LE ORE SONO MENO DI 10, SCRIVI LO ZERO A SINISTRA.
- lcd.print(ore); // STAMPA LE ORE
- lcd.print(":"); // STAMPA I DUE PUNTI
- if (minuti < 10) lcd.print("0"); // SE I MINUTI SONO MENO DI 10, SCRIVI LO ZERO A SINISTRA.
- lcd.print(minuti);
- if (digitalRead(pulsSET)==HIGH);{
- delay(1000);
- lcd.clear();
- lcd.setCursor (1,2);
- lcd.print("TIME-ON IMPOSTATO");
- delay(1000);
- step_funzione=2;}
- if (digitalRead(pulsMENU)==HIGH);{
- delay(1000);
- lcd.clear();
- lcd.setCursor(1,2);
- lcd.print("SET-TIME-ON ANNULLATO");
- delay(1000);
- step_funzione=0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement