This repository was archived by the owner on Sep 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrisciaLed.cpp
More file actions
executable file
·85 lines (64 loc) · 2.14 KB
/
StrisciaLed.cpp
File metadata and controls
executable file
·85 lines (64 loc) · 2.14 KB
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
#include "StrisciaLed.h"
// Mappatura delle righe
// Se parte da sinistra -> false
// Se parte da destra -> true
const bool StrisciaLed::READ_MAP[] = { false, true, false };
StrisciaLed::StrisciaLed(Adafruit_NeoPixel *pixels) {
_pixels = pixels;
_coloreOreOn = _pixels -> Color(0, 0, 255, 255);
_coloreMinutiOn = _pixels -> Color(0, 255, 0, 255);
_coloreSecondiOn = _pixels -> Color(255, 0, 0, 255);
_coloreOreOff = _pixels -> Color(10, 10, 10, 255);
_coloreMinutiOff = _pixels -> Color(10, 10, 10, 255);
_coloreSecondiOff = _pixels -> Color(10, 10, 10, 255);
}
void StrisciaLed::SetHours(uint8_t ore) {
CalcolaLED(ore, READ_MAP[0], _toDraw[0]);
}
void StrisciaLed::SetMinutes(uint8_t minuti) {
CalcolaLED(minuti, READ_MAP[1], _toDraw[1]);
}
void StrisciaLed::SetSeconds(uint8_t secondi) {
CalcolaLED(secondi, READ_MAP[2], _toDraw[2]);
}
void StrisciaLed::CalcolaLED(uint8_t num, bool reverse, bool *out) {
String tmp = String(num, BIN);
for(int i = tmp.length(); i < 7; i++)
tmp = '0' + tmp;
if(!reverse) {
int j = 6;
for(int i = 0; i <= 6; i++) {
out[j--] = tmp[i] == '1';
}
} else {
for(int i = 0; i <= 6; i++) {
out[i] = tmp[i] == '1';
}
}
}
void StrisciaLed::SetBlinking(bool blinking, int pos) {
_blinking[pos] = blinking;
}
void StrisciaLed::Show() {
int i = 21;
uint32_t accesi[] = { _coloreOreOn, _coloreMinutiOn, _coloreSecondiOn };
uint32_t spenti[] = { _coloreOreOff, _coloreMinutiOff, _coloreSecondiOff };
for(int i = 0; i < 3; i++) {
if(_blinking[i])
_rawBlinking[i] = !_rawBlinking[i];
}
for(int j = 2; j >= 0; j--) {
for(int k = 0; k < 7; k++) {
uint32_t coloreAttuale;
if(_blinking[j] && _rawBlinking[j])
coloreAttuale = (_toDraw[j][k] == 1) ? spenti[j] : accesi[j];
else if(_toDraw[j][k] == 1 && !_blinking[j])
coloreAttuale = accesi[j];
else
coloreAttuale = spenti[j];
// Serial.println(_toDraw[j][k]);
_pixels -> setPixelColor(--i, coloreAttuale);
}
}
_pixels -> show();
}