-
Notifications
You must be signed in to change notification settings - Fork 0
/
RgbLedFraschetta.h
59 lines (59 loc) · 1.92 KB
/
RgbLedFraschetta.h
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
#ifndef RgbLedFraschetta_h
#define RgbLedFraschetta_h
#include "LedFraschetta.h"
struct RgbValuesF{
uint8_t Green,Red,Blue;
RgbValuesF(uint8_t Green=0,uint8_t Red=128,uint8_t Blue=0){
this->Green=Green; this->Red=Red; this->Red=Red;
}
void SetBrightness(uint8_t Percentage){
Green=(Percentage*100/Green);
Red=(Percentage*100/Red);
Blue=(Percentage*100/Blue);
}
};
const RgbValuesF GreenColor=RgbValuesF(0,128,0),RedColor=RgbValuesF(255,0,0);
const RgbValuesF BlueColor=RgbValuesF(0,0,255),WhiteColor=RgbValuesF(255,255,255);
class RgbLedF{
protected:
LedF Green,Red,Blue;
RgbValuesF Color;
public:
void SetColor(RgbValuesF Color){
Green.SetAnalogStatus(Color.Green);
Red.SetAnalogStatus(Color.Red);
Blue.SetAnalogStatus(Color.Blue);
}
void SetBrightness(uint8_t Percentage){Color.SetBrightness(Percentage);}
void Blink(uint16_t Period,UnitOfTime Unit){
Green.TurnOff(); Red.TurnOff(); Blue.TurnOff();
Wait(Period,Unit); SetColor(Color);
}
void TurnOnWithFader(uint8_t MaximumPercentage,uint16_t Slow,UnitOfTime Unit){
RgbValuesF ColorChanged = this->Color;
for(uint8_t P=0;P<MaximumPercentage;P++){
ColorChanged.SetBrightness(100+P);
SetColor(ColorChanged);
}
}
void TurnOffWithFader(uint8_t MaximumPercentage,uint16_t Slow,UnitOfTime Unit){
RgbValuesF ColorChanged = this->Color;
for(uint8_t P=0;P>0;P--){
ColorChanged.SetBrightness(100-P);
SetColor(ColorChanged);
}
}
void FadingLoop(uint8_t MaximumPercentage,uint16_t Slow,UnitOfTime Unit){
TurnOnWithFader(MaximumPercentage,Slow,Unit);
TurnOffWithFader(MaximumPercentage,Slow,Unit);
}
void Begin(){Green.Begin(); Red.Begin(); Blue.Begin();}
RgbLedF(uint8_t PinGreen=2,uint8_t PinRed=3,uint8_t PinBlue=4,MemorizeStatus Save=DoNotSaveStatus,RgbValuesF Color=GreenColor){
Green = LedF(PinGreen,Save);
Red = LedF(PinRed,Save);
Blue = LedF(PinBlue,Save);
this->Color=Color;
SetColor(Color);
}
};
#endif