This repository has been archived by the owner on Jun 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay.cpp
130 lines (107 loc) · 3.94 KB
/
display.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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include <Adafruit_NeoPixel.h>
#include "display.h"
static byte displayDigits[] = {
191, /* 0 [00111111] Painting numbers, with numbers. */
6, /* 1 [00000110] */
91, /* 2 [01011011] 1 */
79, /* 3 [01001111] 6 2 */
102, /* 4 [01100110] 7 */
109, /* 5 [01101101] 5 3 */
253, /* 6 [01111101] 4 */
7, /* 7 [00000111] */
255, /* 8 [01111111] */
239, /* 9 [01101111] */
119, /* A [01110111] */
140, /* b [01111100] */
88, /* c [01011000] */
94, /* d [01011110] */
121, /* E [01111001] */
113, /* F [01110001] */
84, /* n [01010100] 16 */
119, /* A [01110111] */
121, /* E [01111001] E is double defined */
56, /* L [00111000] */
57, /* C [00111001] */
};
void DisplayStart(void) {
pixels.setBrightness(10);
pixels.begin();
}
uint32_t Color(uint8_t r, uint8_t g, uint8_t b) {
return pixels.Color(r, g, b);
}
// place starts from zero for the farthest right digit
void DisplaySubliminalMessage(uint32_t color) {
pixels.clear();
for( int currentLetter = 0; currentLetter < 6; currentLetter++) {
for( int seg=0; seg < NUMSEGMENTS; seg++ ) {
if( displayDigits[currentLetter + 16] & (1 << seg) ) {
for( int segLed=0; segLed < LEDSPERSEGMENT; segLed++ ) {
pixels.setPixelColor( (NUMPIXELS - LEDSPERDIGIT) - LEDSPERDIGIT*currentLetter + LEDSPERSEGMENT*seg + segLed - 1, color );
}
}
}
}
//pixels.show(); // This sends the updated pixel color to the hardware.
}
// place starts from zero for the farthest right digit
void DisplayDigit(uint8_t number, uint8_t place, uint32_t color) {
for( int seg=0; seg < NUMSEGMENTS; seg++ ) {
if( displayDigits[number] & (1 << seg) ) {
for( int segLed=0; segLed < LEDSPERSEGMENT; segLed++ ) {
pixels.setPixelColor( (NUMPIXELS - LEDSPERDIGIT) - LEDSPERDIGIT*place + LEDSPERSEGMENT*seg + segLed - 1, color );
}
}
}
//pixels.show(); // This sends the updated pixel color to the hardware.
}
void DisplayHour(uint8_t hour, uint32_t color) {
DisplayDigit(hour%10, 3, color);
if(hour/10 > 0)
DisplayDigit(hour/10, 4, color);
}
void DisplayMinutes(uint8_t minutes, uint32_t color) {
DisplayDigit(minutes%10, 1, color);
DisplayDigit(minutes/10, 2, color);
pixels.setPixelColor(NUMPIXELS-1, color);
}
void DisplayNumber(uint32_t number, uint32_t color, unsigned char show_dot) {
uint32_t currentNumber = 0;
/* int number = a number from 0-99999 */
if(number < 0 || number > MAXDISPLAYVAL) {
return;
}
pixels.clear();
currentNumber = number % 10;
for(uint32_t currentPlace = 0; number > 0; number /= 10, currentNumber = number % 10, ++currentPlace)
{
DisplayDigit( currentNumber, currentPlace, pixels.Color(255, 0, 0) );
}
}
void ClearStrip() {
for(uint16_t i=0; i<pixels.numPixels(); i++) {
pixels.setPixelColor(i, pixels.Color(0,0,0));
}
//pixels.show();
}
void ShowPixels() {
pixels.show();
}
void DisplayDashes(uint32_t color) {
pixels.clear();
int led = 0;
for(int disp = 0; disp < NUMDISPLAYS; disp++){
for(int seg=0; seg < NUMSEGMENTS; seg++) {
if(6 == seg) {
for(int segLed=0; segLed < LEDSPERSEGMENT; segLed++) {
pixels.setPixelColor(led++, color);
}
}
else
{
led += NUMSEGMENTS;
}
}
}
//pixels.show(); // This sends the updated pixel color to the hardware.
}