Sketch Arduino

advertisement
1
2
3
4
5
6
7
// SVEGLIA CON PROGRAMMAZIONE SETTIMANALE
#include <Wire.h>
#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
8 int Hours[7] = {0,6,21,11,8,8,0}; // ORA ACCENSIONE SVEGLIA A PARTIRE DA
DOMENICA
9 int Min[7] =
{0,0,6,18,30,0,0}; // MINUTI ACCENSIONE SVEGLIA A PARTIRE DA
DOMENICA
10 unsigned long time = 5; // minuti di suono buzzer
11 int state = 0;
12
13 RTC_DS1307 RTC;
14
15 void setup () {
16
17
pinMode(rele,OUTPUT); // input del buzzer
18
pinMode(button,INPUT_PULLUP); // input del buzzer
19
Serial.begin(57600); //
20
Wire.begin();
21
RTC.begin();
22
23
if (! RTC.isrunning()) {
24
Serial.println("RTC is NOT running!");
25
// following line sets the RTC to the date & time this sketch was
compiled
26
RTC.adjust(DateTime(F(__DATE__), F(__TIME__)));
27
// This line sets the RTC with an explicit date & time, for example to
set
28
// January 21, 2014 at 3am you would call:
29
//RTC.adjust(DateTime(2014, 9, 05,12,11, 0));
30
}
31
Serial.print("N."); // E' il giorno della settimana. Domenica è zero, lun è
1
32
Serial.print("\t");
33
Serial.print("Giorno");
34
Serial.print("\t\t");
35
Serial.print("Ora");
36
Serial.println();
37
38 }
39
40 void loop () {
41
42
state=digitalRead(button);
43
DateTime now = RTC.now();
44
45
// INSERISCO LA CORREZIONE DEI SECONDI GIORNALIERI
46
if((now.hour()== 2) && (now.minute()== 12) && (now.second()== 04) ){
47
RTC.adjust(DateTime(now.year(), now.month(),
now.day(),now.hour(),now.minute(), now.second()+15));
48
}
49
50
// il rele si attiva al tempo indicato sotto
51
52
if( ( now.hour() >= Hours[now.dayOfWeek()]) && ( now.minute() >=
Min[now.dayOfWeek()]) &&
53
(now.hour() < (Hours[now.dayOfWeek()] +1)) && ( now.minute() <
(Min[now.dayOfWeek()] +time )) &&
54
(week[now.dayOfWeek()])){
55
digitalWrite(rele,HIGH);
56
if(state == LOW){
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82 }
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);
Download
Related flashcards

Neonatology

55 cards

Pediatricians

20 cards

French pediatricians

13 cards

Create Flashcards