-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lamp.cpp
51 lines (40 loc) · 1017 Bytes
/
Lamp.cpp
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
#include "Lamp.h"
Lamp::Lamp(int outputPin)
: dimmer(outputPin)
{ }
void Lamp::setup()
{
this->dimmer.setPower(MIN_INTENSITY); // To prevent the lamp from turning on by default when the whole thing is connected to a power source
dimmer.begin(NORMAL_MODE, ON);
}
void Lamp::setIntensity(int intensity)
{
int intensityToSet = intensity;
if (intensity > MAX_INTENSITY)
intensityToSet = MAX_INTENSITY;
else if (intensity < MIN_INTENSITY)
intensityToSet = MIN_INTENSITY;
int currentIntensity = this->getCurrentIntensity();
if (intensityToSet != currentIntensity)
this->dimmer.setPower(intensityToSet);
}
int Lamp::getCurrentIntensity()
{
return this->dimmer.getPower();
}
void Lamp::brighter()
{
this->setIntensity(this->getCurrentIntensity() + INTENSITY_STEP);
}
void Lamp::darker()
{
this->setIntensity(this->getCurrentIntensity() - INTENSITY_STEP);
}
void Lamp::maxPower()
{
this->setIntensity(MAX_INTENSITY);
}
void Lamp::off()
{
this->setIntensity(MIN_INTENSITY);
}