-
Notifications
You must be signed in to change notification settings - Fork 2
/
smart_bathroom.ino
169 lines (162 loc) · 5.47 KB
/
smart_bathroom.ino
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
#include "neopixel/neopixel.h"
#define PIXEL_PIN D2
#define PIXEL_COUNT 64
#define PIXEL_TYPE WS2812B
#define sensorPin D1;
int sensorData = 0;
int doorStatus = 0;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
Spark.variable("doorStatus", &doorStatus, INT);
}
void loop() {
sensorData = digitalRead(sensorPin);
if (sensorData = 1)
{
doorStatus = 1;
doorClosed();
}
else
{
doorStatus = 0;
doorOpen();
}
}
void doorOpen() {
strip.setPixelColor(0, 0, 0, 0);
strip.setPixelColor(1, 0, 0, 0);
strip.setPixelColor(2, 0, 0, 0);
strip.setPixelColor(3, 0, 0, 0);
strip.setPixelColor(4, 0, 0, 0);
strip.setPixelColor(5, 0, 0, 0);
strip.setPixelColor(6, 0, 0, 0);
strip.setPixelColor(7, 0, 0, 0);
strip.setPixelColor(8, 0, 0, 0);
strip.setPixelColor(9, 0, 0, 0);
strip.setPixelColor(10, 0, 0, 0);
strip.setPixelColor(11, 0, 0, 0);
strip.setPixelColor(12, 0, 0, 0);
strip.setPixelColor(13, 0, 0, 0);
strip.setPixelColor(14, 0, 0, 0);
strip.setPixelColor(15, 0, 0, 0);
strip.setPixelColor(16, 0, 0, 0);
strip.setPixelColor(17, 0, 0, 0);
strip.setPixelColor(18, 0, 0, 0);
strip.setPixelColor(19, 0, 0, 0);
strip.setPixelColor(20, 0, 0, 0);
strip.setPixelColor(21, 0, 0, 0);
strip.setPixelColor(22, 27, 167, 46);
strip.setPixelColor(23, 0, 0, 0);
strip.setPixelColor(24, 0, 0, 0);
strip.setPixelColor(25, 0, 0, 0);
strip.setPixelColor(26, 0, 0, 0);
strip.setPixelColor(27, 0, 0, 0);
strip.setPixelColor(28, 0, 0, 0);
strip.setPixelColor(29, 27, 167, 46);
strip.setPixelColor(30, 0, 0, 0);
strip.setPixelColor(31, 0, 0, 0);
strip.setPixelColor(32, 0, 0, 0);
strip.setPixelColor(33, 0, 0, 0);
strip.setPixelColor(34, 0, 0, 0);
strip.setPixelColor(35, 0, 0, 0);
strip.setPixelColor(36, 27, 167, 46);
strip.setPixelColor(37, 0, 0, 0);
strip.setPixelColor(38, 0, 0, 0);
strip.setPixelColor(39, 0, 0, 0);
strip.setPixelColor(40, 0, 0, 0);
strip.setPixelColor(41, 27, 167, 46);
strip.setPixelColor(42, 0, 0, 0);
strip.setPixelColor(43, 27, 167, 46);
strip.setPixelColor(44, 0, 0, 0);
strip.setPixelColor(45, 0, 0, 0);
strip.setPixelColor(46, 0, 0, 0);
strip.setPixelColor(47, 0, 0, 0);
strip.setPixelColor(48, 0, 0, 0);
strip.setPixelColor(49, 0, 0, 0);
strip.setPixelColor(50, 27, 167, 46);
strip.setPixelColor(51, 0, 0, 0);
strip.setPixelColor(52, 0, 0, 0);
strip.setPixelColor(53, 0, 0, 0);
strip.setPixelColor(54, 0, 0, 0);
strip.setPixelColor(55, 0, 0, 0);
strip.setPixelColor(56, 0, 0, 0);
strip.setPixelColor(57, 0, 0, 0);
strip.setPixelColor(58, 0, 0, 0);
strip.setPixelColor(59, 0, 0, 0);
strip.setPixelColor(60, 0, 0, 0);
strip.setPixelColor(61, 0, 0, 0);
strip.setPixelColor(62, 0, 0, 0);
strip.setPixelColor(63, 0, 0, 0);
strip.setBrightness(30);
strip.show();
}
void doorClosed() {
strip.setPixelColor(0, 0, 0, 0);
strip.setPixelColor(1, 0, 0, 0);
strip.setPixelColor(2, 0, 0, 0);
strip.setPixelColor(3, 0, 0, 0);
strip.setPixelColor(4, 0, 0, 0);
strip.setPixelColor(5, 0, 0, 0);
strip.setPixelColor(6, 0, 0, 0);
strip.setPixelColor(7, 0, 0, 0);
strip.setPixelColor(8, 0, 0, 0);
strip.setPixelColor(9, 185, 30, 0);
strip.setPixelColor(10, 0, 0, 0);
strip.setPixelColor(11, 0, 0, 0);
strip.setPixelColor(12, 0, 0, 0);
strip.setPixelColor(13, 0, 0, 0);
strip.setPixelColor(14, 185, 30, 0);
strip.setPixelColor(15, 0, 0, 0);
strip.setPixelColor(16, 0, 0, 0);
strip.setPixelColor(17, 0, 0, 0);
strip.setPixelColor(18, 185, 30, 0);
strip.setPixelColor(19, 0, 0, 0);
strip.setPixelColor(20, 0, 0, 0);
strip.setPixelColor(21, 185, 30, 0);
strip.setPixelColor(22, 0, 0, 0);
strip.setPixelColor(23, 0, 0, 0);
strip.setPixelColor(24, 0, 0, 0);
strip.setPixelColor(25, 0, 0, 0);
strip.setPixelColor(26, 0, 0, 0);
strip.setPixelColor(27, 185, 30, 0);
strip.setPixelColor(28, 185, 30, 0);
strip.setPixelColor(29, 0, 0, 0);
strip.setPixelColor(30, 0, 0, 0);
strip.setPixelColor(31, 0, 0, 0);
strip.setPixelColor(32, 0, 0, 0);
strip.setPixelColor(33, 0, 0, 0);
strip.setPixelColor(34, 0, 0, 0);
strip.setPixelColor(35, 185, 30, 0);
strip.setPixelColor(36, 185, 30, 0);
strip.setPixelColor(37, 0, 0, 0);
strip.setPixelColor(38, 0, 0, 0);
strip.setPixelColor(39, 0, 0, 0);
strip.setPixelColor(40, 0, 0, 0);
strip.setPixelColor(41, 0, 0, 0);
strip.setPixelColor(42, 185, 30, 0);
strip.setPixelColor(43, 0, 0, 0);
strip.setPixelColor(44, 0, 0, 0);
strip.setPixelColor(45, 185, 30, 0);
strip.setPixelColor(46, 0, 0, 0);
strip.setPixelColor(47, 0, 0, 0);
strip.setPixelColor(48, 0, 0, 0);
strip.setPixelColor(49, 185, 30, 0);
strip.setPixelColor(50, 0, 0, 0);
strip.setPixelColor(51, 0, 0, 0);
strip.setPixelColor(52, 0, 0, 0);
strip.setPixelColor(53, 0, 0, 0);
strip.setPixelColor(54, 185, 30, 0);
strip.setPixelColor(55, 0, 0, 0);
strip.setPixelColor(56, 0, 0, 0);
strip.setPixelColor(57, 0, 0, 0);
strip.setPixelColor(58, 0, 0, 0);
strip.setPixelColor(59, 0, 0, 0);
strip.setPixelColor(60, 0, 0, 0);
strip.setPixelColor(61, 0, 0, 0);
strip.setPixelColor(62, 0, 0, 0);
strip.setPixelColor(63, 0, 0, 0);
strip.setBrightness(30);
strip.show();
}