Sketch Arduino

Download Report

Transcript Sketch Arduino

32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 48 49 50 51 52 53 54 55 56 // SVEGLIA CON PROGRAMMAZIONE SETTIMANALE #include #include "RTClib.h" #define rele 2 #define button 3 boolean week[7] = {0,1,1,1,1,1,0}; // GIORNI DI ATTIVAZIONE SVEGLIA A PARTIRE DA DOMENICA : "0" E' SPENTA "1" E' ACCESA int Hours[7] = {0,6,21,11,8,8,0}; // ORA ACCENSIONE SVEGLIA A PARTIRE DA DOMENICA int Min[7] = {0,0,6,18,30,0,0}; // MINUTI ACCENSIONE SVEGLIA A PARTIRE DA DOMENICA unsigned long time = 5; // minuti di suono buzzer int state = 0; RTC_DS1307 RTC; void setup () { pinMode(rele,OUTPUT); // input del buzzer pinMode(button,INPUT_PULLUP); // input del buzzer Serial.begin(57600); // Wire.begin(); RTC.begin(); if (! RTC.isrunning()) { Serial.println("RTC is NOT running!"); // 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, 9, 05,12,11, 0)); } Serial.print("N."); // E' il giorno della settimana. Domenica è zero, lun è 1 Serial.print("\t"); Serial.print("Giorno"); Serial.print("\t\t"); Serial.print("Ora"); Serial.println(); } void loop () { state=digitalRead(button); DateTime now = RTC.now(); // INSERISCO LA CORREZIONE DEI SECONDI GIORNALIERI if((now.hour()== 2) && (now.minute()== 12) && (now.second()== 04) ){ RTC.adjust(DateTime(now.year(), now.month(), now.day(),now.hour(),now.minute(), now.second()+15)); } // il rele si attiva al tempo indicato sotto if( ( now.hour() >= Hours[now.dayOfWeek()]) && ( now.minute() >= Min[now.dayOfWeek()]) && (now.hour() < (Hours[now.dayOfWeek()] +1)) && ( now.minute() < (Min[now.dayOfWeek()] +time )) && (week[now.dayOfWeek()])){ digitalWrite(rele,HIGH); if(state == LOW){

73 74 75 76 77 78 79 80 81 82 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 digitalWrite(rele,LOW); delay(time*60000); Serial.print("ACCESO"); } }else{ digitalWrite(rele,LOW); } Serial.print(now.dayOfWeek(), DEC); Serial.print('\t'); Serial.print(now.day(), DEC); Serial.print('/'); Serial.print(now.month(), DEC); Serial.print('/'); Serial.print(now.year(), DEC); Serial.print('\t'); Serial.print(now.hour(), DEC); Serial.print(':'); Serial.print(now.minute(), DEC); Serial.print(':'); Serial.print(now.second(), DEC); Serial.println(); delay(1000); }