This repository has been archived by the owner on May 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
RF-temperature-block.ino
248 lines (226 loc) · 7.76 KB
/
RF-temperature-block.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
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
/*
Replacement of my glowing egg http://www.maredana.nl/home-automation/woonkamer-cv-raspberry/
Source: https://github.com/incmve/RF-temperature-block
3D printer model: http://www.thingiverse.com/thing:988027
*/
//Includes
#include "LedControlMS.h"
#include <dht.h>
#include <NewRemoteReceiver.h>
//Define pins
#define NBR_MTX 2 // number of 8x8 displays
#define DHT11_PIN 8 // DHT11 pin
#define ledPinR 3 // Red LED connected to digital pin 5
#define ledPinB 6 // Blue LED connected to digital pin 9
#define ledPinG 5 // Green LED connected to digital pin 6
LedControl lc=LedControl(12,11,10, NBR_MTX); // DataIn,CLK,LOAD, number of displays
// Variables
int NIGHT = 0; // 0 daytime, 1 Night mode
dht DHT;
// 1 = enable debug, 0 = disable debug
boolean debug = 0;
void setup() {
NewRemoteReceiver::init(0, 2, egg); // RF receiver on pin 2
Serial.begin (9600);
Serial.println("Setup");
lc.shutdown(0,false);// turn off power saving, enables display
lc.shutdown(1,false);// turn off power saving, enables display
lc.setIntensity(0,6);// sets brightness (0~15 possible values)
lc.setIntensity(1,6);// sets brightness (0~15 possible values)
lc.clearDisplay(0);// clear screen just in case
lc.clearDisplay(1);// clear screen just in case
}
void loop() {
if (NIGHT == 0) {
lc.shutdown(0,false);
lc.shutdown(1,false);
int chk = DHT.read11(DHT11_PIN);
if (debug) {
Serial.println(chk);
}
switch (chk)
{
case DHTLIB_OK:
float humfloat = DHT.temperature;
int temperature = humfloat - 2;
int ones = (temperature%10); // extract ones from temperature
int tens = ((temperature/10)%10); // extract tens from temperature
if (debug) {
Serial.print("Temp: ");
Serial.println(temperature);
Serial.print("Ones: ");
Serial.println(ones);
Serial.print("Tens: ");
Serial.println(tens);
}
int temp1 = tens;
int temp2 = ones;
lc.displayChar(0 , temp1);
lc.displayChar2(1 , temp2);
delay(10000);
// lc.clearAll();
break;
}
}
if (debug) {
Serial.print("Nightmode: ");
Serial.println(NIGHT);
}
}
void egg(NewRemoteCode receivedCode) {
if (debug) {
// debug RF
Serial.print("Addr ");
Serial.print(receivedCode.address);
if (receivedCode.groupBit) {
Serial.print(" group");
} else {
Serial.print(" unit ");
Serial.print(receivedCode.unit);
}
switch (receivedCode.switchType) {
case 0:
Serial.print(" off");
break;
case 1:
Serial.print(" on");
break;
case 2:
Serial.print(" dim level");
Serial.print(receivedCode.dimLevel);
break;
}
}
if (receivedCode.address == 66 && receivedCode.unit == 6 && receivedCode.switchType == 1) // Unit 66 ID 6 On signal
{
NIGHT = 0;
analogWrite(ledPinR, 0);
analogWrite(ledPinG, 0);
analogWrite(ledPinB, 0);
for(int i = 0; i < 3; i++)
{
delay(500);
// fade in from min to max in increments of 1 points:
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=1) {
// sets the value (range from 0 to 255):
analogWrite(ledPinR, fadeValue);
// wait for 500 milliseconds to see the dimming effect
delay(500);
}
// fade out from max to min in increments of 1 points:
for(int fadeValue = 255 ; fadeValue >= 15; fadeValue -=1) {
// sets the value (range from 0 to 255):
analogWrite(ledPinR, fadeValue);
// wait for 500 milliseconds to see the dimming effect
delay(500);
}
}
}
if (receivedCode.address == 66 && receivedCode.unit == 6 && receivedCode.switchType == 0) // Unit 66 ID 6 Off signal
{
NIGHT = 0;
analogWrite(ledPinR, 0);
analogWrite(ledPinG, 0);
analogWrite(ledPinB, 0);
for(int i = 0; i < 3; i++)
{
delay(500);
// fade in from min to max in increments of 1 points:
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=1) {
// sets the value (range from 0 to 255):
analogWrite(ledPinB, fadeValue);
// wait for 500 milliseconds to see the dimming effect
delay(500);
}
// fade out from max to min in increments of 1 points:
for(int fadeValue = 255 ; fadeValue >= 15; fadeValue -=1) {
// sets the value (range from 0 to 255):
analogWrite(ledPinB, fadeValue);
// wait for 500 milliseconds to see the dimming effect
delay(500);
}
}
}
if (receivedCode.address == 66 && receivedCode.unit == 7 && receivedCode.switchType == 0) // Unit 66 ID 7 Off signal
{
analogWrite(ledPinR, 0);
analogWrite(ledPinG, 0);
analogWrite(ledPinB, 0);
{
BlinkR(ledPinR,10);
delay(50);
}
}
if (receivedCode.address == 66 && receivedCode.unit == 7 && receivedCode.switchType == 1) // Unit 66 ID 7 On signal
{
analogWrite(ledPinR, 0);
analogWrite(ledPinG, 0);
analogWrite(ledPinB, 0);
{
BlinkRB(ledPinR,10);
delay(50);
}
}
if (receivedCode.address == 66 && receivedCode.unit == 8 && receivedCode.switchType == 0) // Unit 66 ID 8 Off signal
{
analogWrite(ledPinR, 0);
analogWrite(ledPinG, 0);
analogWrite(ledPinB, 0);
// Glow Pink
analogWrite(ledPinR, 255);
analogWrite(ledPinG, 51);
analogWrite(ledPinB, 153);
}
if (receivedCode.address == 66 && receivedCode.unit == 8 && receivedCode.switchType == 1) // Unit 66 ID 8 On signal
{
analogWrite(ledPinR, 0);
analogWrite(ledPinG, 0);
analogWrite(ledPinB, 0);
// Glow Green
analogWrite(ledPinG, 255);
}
if (receivedCode.address == 66 && receivedCode.unit == 9 && receivedCode.switchType == 0) // Unit 66 ID 9 Off signal
{
analogWrite(ledPinR, 0);
analogWrite(ledPinG, 0);
analogWrite(ledPinB, 0);
NIGHT = 1; // LED display off
if (debug) {
Serial.print("Nightmode: ");
Serial.println(NIGHT);
}
lc.shutdown(0,true);
lc.shutdown(1,true);
}
if (receivedCode.address == 66 && receivedCode.unit == 9 && receivedCode.switchType == 1) // Unit 66 ID 9 On signal
{
analogWrite(ledPinR, 0);
analogWrite(ledPinG,40);
analogWrite(ledPinB, 0);
}
//Blink routine
}
void BlinkR(int led, int times) //Unit 66 ID 7 On Blink
{
for (int i=0; i< times; i++)
{
digitalWrite(ledPinR,HIGH);
delay (10000);
digitalWrite(ledPinR,LOW);
delay (10000);
}
}
void BlinkRB(int led, int times) //Unit 66 ID 7 Off Blink
{
for (int i=0; i< times; i++)
{
digitalWrite(ledPinB,HIGH);
delay (10000);
digitalWrite(ledPinR,HIGH);
delay (10000);
digitalWrite(ledPinB,LOW);
delay (10000);
digitalWrite(ledPinR,LOW);
delay (10000);
}
}