-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime2.ino
More file actions
259 lines (175 loc) · 5.96 KB
/
time2.ino
File metadata and controls
259 lines (175 loc) · 5.96 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
// 09/09/19
// Shutdown after Alarm - leaving Beacon only operating
//----------------------------------------------------------------------------------
#include <avr/sleep.h>
#include <avr/wdt.h>
//const long onTime = 180000; // (/1000)/60 = ca 3.00 minutes ON
//const int offTime = 450; // x 8 = 1 hour OFF
//const int offTime = 900; // x 8 = 2 hour OFF
//-------------------------watchdog interrupt---------------------------------------
//
ISR (WDT_vect)
{
wdt_disable(); // disable watchdog
} // end of WDT_vect
//-------------------------Pin Assign-----------------------------------------------
//in
int channelOne = 0;
int channelTwo = 1;
int channelThree = 2;
int timePeriod = 4; // delay 3 minutes/60 minutes links adjacent to 328P
//out
int alarmOneSet = 8; //9
int alarmOneReset = 9; //8
int alarmTwoSet = 11; //10
int alarmTwoReset = 10; //11
int alarmThreeSet = 13; //12
int alarmThreeReset = 12; //13
int beaconSet = 15; //14
int beaconReset = 14; //15
int power = 16;
// opto-isolators invert i/o
int active = LOW;
int inactive = HIGH;
int set = HIGH;
int reset = HIGH;
long sleepTime = 0;
//----------------------------------------------------------------------------------
void setup () {
// input
pinMode(channelOne, INPUT);
pinMode(channelTwo, INPUT);
pinMode(channelThree, INPUT);
pinMode(timePeriod, INPUT_PULLUP);
// output
pinMode(alarmOneSet, OUTPUT);
pinMode(alarmOneReset, OUTPUT);
pinMode(alarmTwoSet, OUTPUT);
pinMode(alarmTwoReset, OUTPUT);
pinMode(alarmThreeSet, OUTPUT);
pinMode(alarmThreeReset, OUTPUT);
pinMode(beaconSet, OUTPUT);
pinMode(beaconReset, OUTPUT);
pinMode(power, OUTPUT);
// Reset all Relays to Normal Condition (All Off)
resetAllRelays();
delay(5000); // Settle
if (digitalRead(timePeriod) == LOW) sleepTime = 8;
if (digitalRead(timePeriod) == HIGH) sleepTime = 900; // 2 hours
}
//**********************************BEGIN********************************************
void loop ()
{
Awake ();
for (long i = 0; i <= sleepTime; i++) Sleep(); // wdt wakes every 8 seconds so 450*8=3600/60 minutes = 1 hour or 20 ca = 3minutes
}
//**********************************END*********************************************
//------------------------Awake Period-----------------------------------------------
void Awake()
{
digitalWrite(power, active); // turn on OSA/SET/Other
delay(120000); // Wait 2 minutes then check for any alarms 2 minutes = 120000
// Channel One
if (digitalRead(channelOne) == active)
{
alarmOneActive();
beaconActive();
}
/* // Channel Two
if (digitalRead(channelTwo) == active)
{
alarmTwoActive();
beaconActive();
}
// Channel Three
if (digitalRead(channelThree) == active)
{
alarmThreeActive();
beaconActive();
}
*/
digitalWrite(power, inactive); // turn off OSA/SET/Other - Go back to sleep
sleepTime = 1875000;
}
//------------------------Sleep Period----------------------------------------------
void Sleep()
{
// disable ADC
ADCSRA = 0;
// clear various "reset" flags
MCUSR = 0;
// allow changes, disable reset
WDTCSR = bit (WDCE) | bit (WDE);
// set interrupt mode and an interval
WDTCSR = bit (WDIE) | bit (WDP3) | bit (WDP0); // set WDIE, and 8 seconds delay
wdt_reset(); // pat the dog
set_sleep_mode (SLEEP_MODE_PWR_DOWN);
noInterrupts (); // timed sequence follows
sleep_enable();
// turn off brown-out enable in software
MCUCR = bit (BODS) | bit (BODSE);
MCUCR = bit (BODS);
interrupts (); // guarantees next instruction executed
sleep_cpu ();
// After Wakeup Cancel Sleep as a precaution
sleep_disable();
}
//---------------------Reset all Latch Relays -------------------------------------
void resetAllRelays()
{
digitalWrite (alarmOneSet, LOW); // on Latch Relay 1
delay(100) ;
digitalWrite (alarmOneSet, HIGH); // off
digitalWrite (alarmOneReset, LOW); // on
delay(100) ;
digitalWrite (alarmOneReset, HIGH); // off
delay(100) ;
digitalWrite (alarmTwoSet, LOW); // on Latch Relay 2
delay(100) ;
digitalWrite (alarmTwoSet, HIGH); // off
digitalWrite (alarmTwoReset, LOW); // on
delay(100) ;
digitalWrite (alarmTwoReset, HIGH); // off
digitalWrite (alarmThreeSet, LOW); // on Latch Relay 3
delay(100) ;
digitalWrite (alarmThreeSet, HIGH); // off
digitalWrite (alarmThreeReset, LOW); // on
delay(100) ;
digitalWrite (alarmThreeReset, HIGH); // off
digitalWrite (beaconSet, LOW); // on Latch Relays 4 & 5
delay(100) ;
digitalWrite (beaconSet, HIGH); // off
digitalWrite (beaconReset, LOW); // on
delay(100) ;
digitalWrite (beaconReset, HIGH); // off
delay(100) ;
digitalWrite(power, inactive);
}
//------------------------Alarm One Enable-------------------------------------------
void alarmOneActive()
{
digitalWrite (alarmOneSet, LOW); // on
delay(1000);
digitalWrite (alarmOneSet, HIGH); //off Set Latch Relay 1
}
//------------------------Alarm Two Enable-------------------------------------------
void alarmTwoActive()
{
digitalWrite (alarmTwoSet, LOW); // on
delay(1000);
digitalWrite (alarmTwoSet, HIGH); //off Set Latch Relay 2
}
//------------------------Alarm Three Enable-----------------------------------------
void alarmThreeActive()
{
digitalWrite (alarmThreeSet, LOW); // on
delay(1000);
digitalWrite (alarmThreeSet, HIGH); //off Set Latch Relay 3
}
//------------------------Beacon/Global Enable----------------------------------------
void beaconActive()
{
digitalWrite (beaconSet, LOW); // on
delay(1000);
digitalWrite (beaconSet, HIGH); //off Set Latch Relays 4 & 5
}