Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include "RTClib.h"
- RTC_DS3231 rtc;
- char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
- #include "DHT.h"// definisco il pin del sensore
- #define DHTPIN 31// definisco il tipo di sensore
- #define DHTTYPE DHT11
- DHT dht(DHTPIN, DHTTYPE);
- #include <EEPROM.h>
- #include <Nextion.h>
- #include <NextionPage.h>
- #include <NextionDualStateButton.h>
- #include <NextionNumber.h>
- #include <NextionText.h>
- #include <NextionButton.h>
- Nextion nex(Serial1);
- NextionDualStateButton bMain(nex, 7, 4, "b12v");
- NextionDualStateButton bventola(nex, 7, 5, "bventola");
- NextionDualStateButton bSMS(nex, 5, 1, "bSMS");
- NextionDualStateButton bcicalino(nex, 5, 6, "bcicalino");
- NextionDualStateButton ModeAUTO(nex, 5, 5, "bauto");
- NextionDualStateButton bluce(nex, 7, 1, "bluce");// DICHUIARAZIONE PULSANTE!!!!!(pagina,id,nome)
- NextionDualStateButton bmandrino(nex, 5, 12, "bmandrino");
- NextionNumber Vtemperatura(nex, 6, 1, "temperatura");// prova
- NextionNumber Vumidita(nex, 6, 3, "umidita");
- NextionNumber Vtensione(nex, 6, 5, "tensione");
- NextionNumber Vcorrente(nex, 6, 7, "corrente");
- NextionText Vorario(nex, 3, 7, "ora");
- NextionNumber Vcica(nex, 5, 9, "ncica");
- NextionButton bmute(nex, 3, 4, "bmute");
- int finecorsa = 22;
- int mandrino = 27;
- int main12v = 42;//27;
- int selettoresms;
- int led = 28;
- int cicalino = 26;
- int ventola = 29;
- int statofinecorsa;
- int statoselettoresms;
- int statomessaggio = 0;
- int timer;
- int selettorecicalino;
- int tempo = 1000;
- int Stensione = A0;
- char bf[20];
- int selettoremodeAUTO;
- int tempoaggiornamento;
- int mute;
- int mandrinoMAN;
- unsigned long tm1;
- int valletto;
- float tensione;
- int temperatura ;
- int umidita ;
- void setup()
- {
- Serial.begin(115200);
- Serial1.begin(115200);
- Serial2.begin(9600);
- delay(3000);
- if (! rtc.begin()) {
- Serial.println("Couldn't find RTC");
- while (1);
- }
- if (rtc.lostPower()) {
- Serial.println("RTC lost power, lets set the time!");
- // following line sets the RTC to the date & time this sketch was compiled
- // rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
- // This line sets the RTC with an explicit date & time, for example to set
- // January 21, 2014 at 3am you would call:
- // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
- }
- nex.init();
- pinMode(finecorsa, INPUT_PULLUP);
- pinMode(cicalino, OUTPUT);
- pinMode(mandrino, OUTPUT);
- pinMode(led, OUTPUT);
- pinMode(main12v, OUTPUT);
- pinMode(ventola, OUTPUT);
- digitalWrite(ventola, HIGH);
- digitalWrite(main12v, HIGH);
- digitalWrite(led, HIGH);
- digitalWrite(cicalino, HIGH);
- Vorario.setText(bf);
- bventola.attachCallback(&callback);
- bluce.attachCallback(&callback1);
- bSMS.attachCallback(&callback2);
- bMain.attachCallback(&callback3);
- bcicalino.attachCallback(&callback4);
- bmandrino.attachCallback(&callback5);
- ModeAUTO.attachCallback(&callback6);
- bmute.attachCallback(&callback7);
- tm1=millis();
- }
- void loop() {
- nex.poll();
- valletto = analogRead(Stensione); //This divider module will divide the measured voltage by 5, the maximum voltage it can measure is 25V.
- tensione = valletto / 41;
- if (millis()-tm1>(unsigned long)(3000)){
- //Vtemperatura.setValue(temperatura);
- //Vumidita.setValue( umidita);
- //Vtensione.setValue(tensione);
- //Vcorrente.setValue(100);
- temperatura = dht.readTemperature();
- umidita = dht.readHumidity();
- valletto = analogRead(Stensione); //This divider module will divide the measured voltage by 5, the maximum voltage it can measure is 25V.
- tensione = valletto / 41;
- DateTime now = rtc.now();
- sprintf(bf,"%02d/%02d/%d %02d:%02d",now.day(),now.month(), now.year(),now.hour(),now.minute());
- Vorario.setText(bf);
- tm1=millis();}
- statofinecorsa = digitalRead(finecorsa);
- Serial.print(" selettorecicalino ");
- Serial.print(selettorecicalino);
- Serial.print(" statoselettoresms ");
- Serial.print(statoselettoresms);
- Serial.print(" statofinecorsa ");
- Serial.print(statofinecorsa);
- Serial.print(" ModeAUTO ");
- Serial.print(selettoremodeAUTO);
- Serial.print(" tempoaggiornamento ");
- Serial.print(tempoaggiornamento);
- Serial.print(" mute ");
- Serial.print(mute);
- Serial.print(" timer ");
- Serial.println(timer);
- if (statofinecorsa == HIGH ) { // finecorsa premuto
- timer++;
- if (timer > tempo ) {
- if ( statoselettoresms == 1 && statomessaggio == 0 && selettorecicalino == 0) {
- Serial2.println("AT");
- delay(500);
- Serial2.println("AT+CSCA=\"+393359609600\""); // Centro Messaggi TIM
- delay(500);
- Serial2.println("AT+CMGF=1\r");
- delay(500);
- Serial2.println("AT+CMGS=\"+393460399387\"");
- delay(500);
- Serial2.print("PROGRAMMA FINITO ");
- delay(500);
- Serial2.println((char)26);
- delay(1000);
- }
- statomessaggio = 1;
- timer = 0;
- }
- }
- if ( statofinecorsa == LOW && selettoremodeAUTO == 1) {
- statomessaggio = 0;
- timer = 0;
- digitalWrite(mandrino , HIGH);
- mute=0;
- }
- if ( statofinecorsa == HIGH && selettoremodeAUTO == 1) {
- statomessaggio = 0;
- timer = 0;
- digitalWrite(mandrino , LOW);
- }
- if (selettorecicalino == 1 && statofinecorsa == HIGH && mute == 0){
- if(timer<100 && timer>0){
- digitalWrite(cicalino , HIGH);}
- if(timer>100 && timer<200){
- digitalWrite(cicalino , LOW );}
- if(timer>200 && timer<300){
- digitalWrite(cicalino , HIGH);}
- if(timer>300 && timer<400){
- digitalWrite(cicalino , LOW );}
- if(timer>400 && timer<500){
- digitalWrite(cicalino , HIGH );}
- if(timer>500 && timer<600){
- digitalWrite(cicalino , LOW );}
- if(timer>600 && timer<700){
- digitalWrite(cicalino , HIGH );}
- if(timer>700 && timer<800){
- digitalWrite(cicalino , LOW );}
- if(timer>800 && timer<900){
- digitalWrite(cicalino , HIGH );}
- }
- if (mute == 1 && selettorecicalino == 1){
- digitalWrite(cicalino , LOW );
- }
- if (mandrinoMAN ==1 ){
- digitalWrite(mandrino, HIGH);
- }
- }
- void callback(NextionEventType type, INextionTouchable *widget)
- {
- if (type == NEX_EVENT_POP)
- {
- if (widget->getNumberProperty("val") == 0)
- digitalWrite(ventola, HIGH);
- else
- digitalWrite(ventola, LOW);
- }
- }
- void callback1(NextionEventType type, INextionTouchable *widget)
- {
- if (type == NEX_EVENT_POP)
- {
- if (widget->getNumberProperty("val") == 0)
- digitalWrite(led, HIGH);
- else
- digitalWrite(led, LOW);
- }
- }
- void callback2(NextionEventType type, INextionTouchable *widget)
- {
- if (type == NEX_EVENT_POP)
- {
- if (widget->getNumberProperty("val") == 0)
- statoselettoresms =0;
- else
- statoselettoresms =1;
- }
- }
- void callback3(NextionEventType type, INextionTouchable *widget)
- {
- if (type == NEX_EVENT_POP)
- {
- if (widget->getNumberProperty("val") == 0)
- digitalWrite(main12v, HIGH);
- else
- digitalWrite(main12v, LOW);
- }
- }
- void callback4(NextionEventType type, INextionTouchable *widget)
- {
- if (type == NEX_EVENT_POP)
- {
- if (widget->getNumberProperty("val") == 0)
- selettorecicalino=0;
- else
- selettorecicalino=1;
- }
- }
- void callback5(NextionEventType type, INextionTouchable *widget)
- {{if (type == NEX_EVENT_POP)
- {
- if (widget->getNumberProperty("val") == 0)
- mandrinoMAN =0;
- else
- mandrinoMAN =1;
- }
- }
- }
- void callback6(NextionEventType type, INextionTouchable *widget)
- {if (type == NEX_EVENT_POP)
- {
- if (widget->getNumberProperty("val") == 0)
- selettoremodeAUTO =0;
- else
- selettoremodeAUTO =1;
- }
- }
- void callback7(NextionEventType type, INextionTouchable *widget)
- {if (type == NEX_EVENT_POP)
- {
- if (widget->getNumberProperty("val") == 0)
- mute=1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement