Skip to content

Commit cb450e7

Browse files
authored
Merge pull request #181 from AlexxBoo/fibonacci256
Tweaks for Analog Clock
2 parents f3651f2 + 0ee4779 commit cb450e7

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

Map.h

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,17 @@ void andPixelAR(uint8_t angle, uint8_t dAngle, uint8_t startRadius, uint8_t endR
7878

7979
void antialiasPixelAR(uint8_t angle, uint8_t dAngle, uint8_t startRadius, uint8_t endRadius, CRGB color)
8080
{
81-
uint16_t amax = qadd8(angle, dAngle);
82-
uint8_t amin = qsub8(angle, dAngle);
83-
8481
for (uint16_t i = 0; i < NUM_LEDS; i++) {
8582
uint8_t o = i;
8683

8784
uint8_t ao = angles[o];
8885

89-
uint8_t adiff = qsub8(max(ao, angle), min(ao, angle));
90-
uint8_t fade = qmul8(adiff, 32);
86+
uint8_t adiff = min(sub8(ao,angle), sub8(angle, ao));
87+
uint8_t fade = map(adiff, 0, dAngle, 0, 255);
9188
CRGB faded = color;
9289
faded.fadeToBlackBy(fade);
9390

94-
if (ao <= amax && ao >= amin) {
91+
if (adiff <= dAngle) {
9592
uint8_t ro = physicalToFibonacci[o];
9693

9794
if (ro <= endRadius && ro >= startRadius) {
@@ -208,20 +205,22 @@ void drawAnalogClock() {
208205
float minute = timeClient.getMinutes() + (second / 60.0);
209206
float hour = timeClient.getHours() + (minute / 60.0);
210207

211-
static uint8_t hourAngle = 0;
212-
static uint8_t minuteAngle = 0;
213-
static uint8_t secondAngle = 0;
214-
215208
const uint8_t hourRadius = 96;
216209
const uint8_t minuteRadius = 192;
217210
const uint8_t secondRadius = 255;
218211

219-
const uint8_t handWidth = 32;
212+
const uint8_t hourHandWidth = 8;
213+
const uint8_t minuteHandWidth = 7;
214+
const uint8_t secondHandWidth = 6;
220215

221216
const float degreesPerSecond = 255.0 / 60.0;
222217
const float degreesPerMinute = 255.0 / 60.0;
223218
const float degreesPerHour = 255.0 / 12.0;
224219

220+
static uint8_t hourAngle = 255 - hour * degreesPerHour;
221+
static uint8_t minuteAngle = 255 - minute * degreesPerMinute;
222+
static uint8_t secondAngle = 255 - second * degreesPerSecond;
223+
225224
EVERY_N_MILLIS(100) {
226225
hourAngle = 255 - hour * degreesPerHour;
227226
minuteAngle = 255 - minute * degreesPerMinute;
@@ -230,9 +229,9 @@ void drawAnalogClock() {
230229

231230
fadeToBlackBy(leds, NUM_LEDS, clockBackgroundFade);
232231

233-
antialiasPixelAR(secondAngle, handWidth, 0, secondRadius, CRGB::Blue);
234-
antialiasPixelAR(minuteAngle, handWidth, 0, minuteRadius, CRGB::Green);
235-
antialiasPixelAR(hourAngle, handWidth, 0, hourRadius, CRGB::Red);
232+
antialiasPixelAR(secondAngle, secondHandWidth, 0, secondRadius, CRGB::Blue);
233+
antialiasPixelAR(minuteAngle, minuteHandWidth, 0, minuteRadius, CRGB::Green);
234+
antialiasPixelAR(hourAngle, hourHandWidth, 0, hourRadius, CRGB::Red);
236235
leds[0] = CRGB::Red;
237236
}
238237

0 commit comments

Comments
 (0)