forked from luon/wordclock
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
This commit is contained in:
parent
6de020aed1
commit
6ac27a1183
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue