From 6ac27a118375c8680b85e83224d6c886e50d04e3 Mon Sep 17 00:00:00 2001 From: Admar Schoonen Date: Sun, 8 Jan 2012 21:36:59 +0100 Subject: [PATCH] Added build option to round() time instead set DISPLAYTIME_MODE to round to have maximum error of 2.5 minutes, set to floor to have traditional display mode with maximum error of 5 minutes --- wordclock/Dutch.h | 146 ++++++++++++++++++++++++++++++++++- wordclock/settings_example.h | 14 ++++ wordclock/wordclock.ino | 6 +- 3 files changed, 162 insertions(+), 4 deletions(-) diff --git a/wordclock/Dutch.h b/wordclock/Dutch.h index 4166325..8dce00e 100644 --- a/wordclock/Dutch.h +++ b/wordclock/Dutch.h @@ -106,10 +106,145 @@ void selftest(void){ } +void displaytime_round(void) +{ + int n; + + // compute the number of seconds that we are in the hour + n = 60 * minute + second; + + // start by clearing the display to a known state + ledsoff(); + + // Now, turn on the "It is" leds + ITIS; + // now we display the appropriate minute counter + if ((n >= 2 * 60 + 30) && (n < 7 * 60 + 30)) { MFIVE; PAST; } + if ((n >= 7 * 60 + 30) && (n < 12 * 60 + 30)) { MTEN; PAST; } + if ((n >= 12 * 60 + 30) && (n < 17 * 60 + 30)) { QUARTER; PAST; } + if ((n >= 17 * 60 + 30) && (n < 22 * 60 + 30)) { MTEN; TO; HALF; } + if ((n >= 22 * 60 + 30) && (n < 27 * 60 + 30)) { MFIVE; TO; HALF; } + if ((n >= 27 * 60 + 30) && (n < 32 * 60 + 30)) { HALF; } + if ((n >= 32 * 60 + 30) && (n < 37 * 60 + 30)) { MFIVE; PAST; HALF; } + if ((n >= 37 * 60 + 30) && (n < 42 * 60 + 30)) { MTEN; PAST; HALF; } + if ((n >= 42 * 60 + 30) && (n < 47 * 60 + 30)) { QUARTER; TO; } + if ((n >= 47 * 60 + 30) && (n < 52 * 60 + 30)) { MTEN; TO; } + if ((n >= 52 * 60 + 30) && (n < 57 * 60 + 30)) { MFIVE; TO; } -void displaytime(void){ + if ((n >= 57 * 60 + 30) || (n < 2 * 60 + 30)) + { + switch (hour) { + case 1: + case 13: ONE; break; + case 2: + case 14: TWO; break; + case 3: + case 15: THREE; break; + case 4: + case 16: FOUR; break; + case 5: + case 17: HFIVE; break; + case 6: + case 18: SIX; break; + case 7: + case 19: SEVEN; break; + case 8: + case 20: EIGHT; break; + case 9: + case 21: NINE; break; + case 10: + case 22: HTEN; break; + case 11: + case 23: ELEVEN; break; + case 0: + case 12: + case 24: TWELVE; break; + } + HOUR; + } + else + { + //if ((minute < 20) && (minute >4)) + if ((n > 2 * 60 + 30) && (n < 17 * 60 + 30)) + { + switch (hour) { + case 1: + case 13: ONE; break; + case 2: + case 14: TWO; break; + case 3: + case 15: THREE; break; + case 4: + case 16: FOUR; break; + case 5: + case 17: HFIVE; break; + case 6: + case 18: SIX; break; + case 7: + case 19: SEVEN; break; + case 8: + case 20: EIGHT; break; + case 9: + case 21: NINE; break; + case 10: + case 22: HTEN; break; + case 11: + case 23: ELEVEN; break; + case 0: + case 12: + case 24: TWELVE; break; + } + } + else + { + // if we are greater than 34 minutes past the hour then display + // the next hour + + switch (hour) { + case 1: + case 13: TWO; break; + case 14: + case 2: THREE; break; + case 15: + case 3: FOUR; break; + case 4: + case 16: HFIVE; break; + case 5: + case 17: SIX; break; + case 6: + case 18: SEVEN; break; + case 7: + case 19: EIGHT; break; + case 8: + case 20: NINE; break; + case 9: + case 21: HTEN; break; + case 10: + case 22: ELEVEN; break; + case 11: + case 23: TWELVE; break; + case 0: + case 12: + case 24: ONE; break; + } + } + } + + // now we can illuminate the extra minute LEDs + + if ((minute-(minute/5)*5)==1) { LED1; } + if ((minute-(minute/5)*5)==2) { LED1; LED2; } + if ((minute-(minute/5)*5)==3) { LED3; LED4; } + if ((minute-(minute/5)*5)==4) { LED4; } + +// WriteLEDs(); + +} + +void displaytime_floor(void) +{ // start by clearing the display to a known state ledsoff(); @@ -242,3 +377,12 @@ void displaytime(void){ } +void displaytime() +{ + #if (DISPLAYTIME == round) + displaytime_round(); + #else + displaytime_floor(); + #endif +} + diff --git a/wordclock/settings_example.h b/wordclock/settings_example.h index 6835301..0afaaab 100644 --- a/wordclock/settings_example.h +++ b/wordclock/settings_example.h @@ -10,6 +10,20 @@ // set SKIPSELFTEST to 1 to skip selftest #define SKIPSELFTEST 1 +// DISPLAYTIME_MODE can either be displaytime_floor or displaytime_round: +// +// * floor: floor() (or truncate) the time to chunks of 5 minutes and where the +// additional 4 leds indicate the number of minutes you have to add to get the +// exact time. Thus, if you only look at the words, you have a maximum error +// of 4 minutes and 59 seconds. This is the traditional mode. +// +// * round: rounds the time to chunks of 5 minutes and where the two additional +// leds indicate if you have to add or subtract 1 or 2 minutes to get the +// exact time. Thus, if you only look at the words, you have a maximum error +// of 2 minutes and 29 seconds. +// +#define DISPLAYTIME_MODE floor + // set USELIGHTSENSOR to 1 to use ambient light sensor connected to ADC0 (pin // 23) #define USELIGHTSENSOR 1 diff --git a/wordclock/wordclock.ino b/wordclock/wordclock.ino index 7e25aa2..9cf7475 100644 --- a/wordclock/wordclock.ino +++ b/wordclock/wordclock.ino @@ -742,12 +742,12 @@ static int lightsensor_thread(struct pt *pt) current_brightness = ambient_light_to_brightness[lightlevel_avg]; - /*Serial.print("D: lightsensor: "); + Serial.print("D: lightsensor: "); Serial.print(lightlevel_sample); Serial.print(", avg: "); Serial.print(lightlevel_avg); Serial.print(", brightness: "); - Serial.println(current_brightness);*/ + Serial.println(current_brightness); } PT_END(pt); @@ -817,7 +817,7 @@ static int wordclock_thread(struct pt *pt) second++; //test to see if we need to increment the time counters - if (second==60) + if ((second==60) || (second == 30)) { incrementtime(); displaytime();