-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathringclockfunctions.ino
More file actions
86 lines (71 loc) · 2.76 KB
/
ringclockfunctions.ino
File metadata and controls
86 lines (71 loc) · 2.76 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
86
/**
* @file ringclockfunctions.ino
*
* @brief This file contains all functions used to control clock related functions
*/
#include "constants.h"
#define MILLIS_PER_MINUTE 60000
/**
* @brief Show the hour on the clock
*
* @param hour hour to show
* @param color color to use
*/
void showHour(uint8_t hour, uint32_t color) {
// clear matrix
ledrings.flushInnerRing();
// convert 24h to 12h
if(hour > 12) {
hour -= 12;
}
ledrings.setPixelInnerRing(hour-1, color);
}
void showMinutes(uint8_t minutes, uint32_t colorMinutes, uint32_t colorSeconds) {
static uint8_t lastMinutes = 0;
static uint32_t timeOfLastMinuteChange = 0;
static uint32_t black = LEDRings::Color24bit(0, 0, 0);
// check if minutes changed
if(minutes != lastMinutes) {
timeOfLastMinuteChange = millis();
lastMinutes = minutes;
}
// calculate time since last minute change
uint32_t timeSinceLastMinuteChange = millis() - timeOfLastMinuteChange;
// calculate seconds progress
float progressSeconds = (float)timeSinceLastMinuteChange / (float)MILLIS_PER_MINUTE;
int activePixelSeconds = (int)(progressSeconds * OUTER_RING_LED_COUNT);
float pixelProgressSeconds = progressSeconds * OUTER_RING_LED_COUNT - activePixelSeconds;
// calculate minutes progress
float minutesContinuous = (float)minutes + progressSeconds;
float progressMinutes = (float)minutesContinuous / 60.0;
int activePixelMinutes = (int)(progressMinutes * OUTER_RING_LED_COUNT);
float pixelProgressMinutes = progressMinutes * OUTER_RING_LED_COUNT - activePixelMinutes;
// clear led ring
ledrings.flushOuterRing();
for(int i = 0; i < OUTER_RING_LED_COUNT; i++) {
if(i == activePixelSeconds - 1){
uint32_t color = LEDRings::interpolateColor24bit(black, colorSeconds, (1 - pixelProgressSeconds));
ledrings.setPixelOuterRing(i, color);
}
else if(i == activePixelSeconds){
uint32_t color = LEDRings::interpolateColor24bit(black, colorSeconds, pixelProgressSeconds);
ledrings.setPixelOuterRing(i, color);
}
else {
if(i < activePixelMinutes) {
ledrings.setPixelOuterRing(i, colorMinutes);
}
else if(i == activePixelMinutes) {
uint32_t color = LEDRings::interpolateColor24bit(black, colorMinutes, pixelProgressMinutes);
ledrings.setPixelOuterRing(i, color);
}
else {
ledrings.setPixelOuterRing(i, black);
}
}
}
}
void showTimeOnClock(uint8_t hour, uint8_t minutes, uint32_t colorHours, uint32_t colorMinutes, uint32_t colorSeconds) {
showHour(hour, colorHours);
showMinutes(minutes, colorMinutes, colorSeconds);
}