-
Notifications
You must be signed in to change notification settings - Fork 0
/
autolight.ino
62 lines (53 loc) · 1.22 KB
/
autolight.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
#include <Arduino.h>
#include "OperationStatus.h"
#include "HumanPresenceDetector.h"
#include "RoomBrightnessDetector.h"
#include "DesiredBrightnessReader.h"
#include "Lamp.h"
OperationStatus operationStatus(5);
Lamp lamp(8);
HumanPresenceDetector humanPresenceDetector(7);
RoomBrightnessDetector roomBrightnessDetector(A0);
DesiredBrightnessReader desiredBrightnessReader(A1);
void setup()
{
Serial.begin(115200);
lamp.setup();
}
void autoAdjustIntensity()
{
int roomBrightness = roomBrightnessDetector.getRoomBrightness();
int desiredBrightness = desiredBrightnessReader.get();
if (abs(desiredBrightness - roomBrightness) < 20)
return;
if (roomBrightness < desiredBrightness)
lamp.brighter();
else if (roomBrightness > desiredBrightness)
lamp.darker();
}
void loop()
{
if (!humanPresenceDetector.humanPresenceDetected())
{
lamp.darker();
}
else
{
int currentOperationStatus = operationStatus.read();
switch (currentOperationStatus)
{
case OperationStatus::OFF:
lamp.darker();
break;
case OperationStatus::AUTO:
autoAdjustIntensity();
break;
case OperationStatus::ON:
lamp.brighter();
break;
default:
break;
}
}
delay(10);
}