-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow_sensor.ino
More file actions
104 lines (87 loc) · 2.55 KB
/
window_sensor.ino
File metadata and controls
104 lines (87 loc) · 2.55 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
#include <avr/sleep.h>
#include <avr/interrupt.h>
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
#define key1 111111 // signal: closed
#define key2 222222 // signal: tilt
#define key3 333333 // signal: open
const int switchPin = 3; // interrupt pin, 1st reed
const int switchPin_2 = 1; // 2nd reed
const int statusLED = 4; // led
int val = 0;
int val_2 = 0;
void setup() {
mySwitch.enableTransmit(2);
pinMode(switchPin, INPUT);
pinMode(switchPin_2, INPUT);
digitalWrite(switchPin, LOW);
digitalWrite(switchPin_2, LOW);
pinMode(statusLED, OUTPUT);
// start
digitalWrite(statusLED, HIGH);
delay(100);
digitalWrite(statusLED, LOW);
}
void sleep() {
GIMSK |= _BV(PCIE);
PCMSK |= _BV(PCINT3);
ADCSRA &= ~_BV(ADEN);
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sei();
sleep_cpu();
cli();
PCMSK &= ~_BV(PCINT3);
sleep_disable();
ADCSRA |= _BV(ADEN);
sei();
}
ISR(PCINT0_vect) {
}
void loop() {
sleep();
// led, awaken info
delay(200);
digitalWrite(statusLED, HIGH);
delay(200);
digitalWrite(statusLED, LOW);
// long delay, for example: tilting window from open state can take some time for human ;)
delay(5000);
// reeds reading
val = digitalRead(switchPin);
val_2 = digitalRead(switchPin_2);
// sending
if (val == 0)
{
for (int i = 0; i <= 2; i++)
{
digitalWrite(statusLED, HIGH);
mySwitch.send(key1, 20);
delay(100);
digitalWrite(statusLED, LOW);
delay(100);
}
}
if (val == 1 and val_2 == 1)
{
for (int i = 0; i <= 2; i++)
{
digitalWrite(statusLED, HIGH);
mySwitch.send(key3, 20);
delay(100);
digitalWrite(statusLED, LOW);
delay(100);
}
}
if (val == 1 and val_2 == 0)
{
for (int i = 0; i <= 2; i++)
{
digitalWrite(statusLED, HIGH);
mySwitch.send(key2, 20);
delay(100);
digitalWrite(statusLED, LOW);
delay(100);
}
}
}