This repository has been archived by the owner on Mar 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LedControl.cpp
54 lines (44 loc) · 1.47 KB
/
LedControl.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
52
53
54
#include "LedControl.h"
LedControl::LedControl(uint8_t _pinWhite) : pinWhite(_pinWhite)
{
SetWhiteBrightness(0xFF);
SetRGBBrightness(0xFF);
SetRGBBackground(Color::Black);
}
void LedControl::Init()
{
pinMode(pinWhite, OUTPUT);
Tlc.init(0);
}
void LedControl::SetWhiteBrightness(uint8_t level)
{
brightnessWhite = level;
}
void LedControl::SetRGBBrightness(uint8_t level)
{
brightnessRGB = level;
}
void LedControl::SetRGBLed(uint8_t led, const Color& color)
{
if(led >= 0 && led < LEDS)
RGBColorData[led].SetColor(color);
}
void LedControl::SetRGBBackground(const Color& color)
{
for(uint8_t led = 0; led < LEDS; ++led)
SetRGBLed(led, color);
}
void LedControl::Update() const
{
analogWrite(pinWhite, brightnessWhite);
for(uint8_t led = 0; led < LEDS; ++led)
{
//Tlc.set(pinR[led], map(static_cast<long>(brightnessRGB)* RGBColorData[led].r * RED_MAX / 255, 0L, 255L * 255L, 0L, 4095L));
//Tlc.set(pinG[led], map(static_cast<long>(brightnessRGB)* RGBColorData[led].g * GREEN_MAX / 255, 0L, 255L * 255L, 0L, 4095L));
//Tlc.set(pinB[led], map(static_cast<long>(brightnessRGB)* RGBColorData[led].b * BLUE_MAX / 255, 0L, 255L * 255L, 0L, 4095L));
Tlc.set(pinR[led], (4095ULL * brightnessRGB * RGBColorData[led].r * RED_MAX) / (255UL * 255 * 255));
Tlc.set(pinG[led], (4095ULL * brightnessRGB * RGBColorData[led].g * GREEN_MAX) / (255UL * 255 * 255));
Tlc.set(pinB[led], (4095ULL * brightnessRGB * RGBColorData[led].b * BLUE_MAX) / (255UL * 255 * 255));
}
Tlc.update();
}