Mired in code
Check-in [8c3827ffa1]
Not logged in
Public Repositories
mwm's Repositories

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Update to latest version of the Watch code.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:8c3827ffa11b29e403beda0ddf5eb977c17af80f
User & Date: mwm@mired.org 2013-03-17 22:47:31
Context
2015-04-18
02:06
Add the maze program. check-in: dcabad86a6 user: mwm tags: trunk
2013-03-17
22:47
Update to latest version of the Watch code. check-in: 8c3827ffa1 user: mwm@mired.org tags: trunk
2013-03-16
03:56
Add my binary clock for Arduino. check-in: 48da261cc6 user: mwm@mired.org tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Arduino/Watch/Watch.ino.

     9      9   
    10     10   /*
    11     11    * Sets of pins used for the LED displays.
    12     12    * These are LSB first, with a trailing 0 to indicate the last LED in the set.
    13     13    * Note that this means we can't drive an LED with pin 0. Use it for a switch.
    14     14    */
    15     15   static int dow_pins[] = {4, 3, 2, 0} ;
    16         -static int ampm_pins[] = {18, 17, 0} ;
    17         -static int hour_pins[] = {9, 8, 7, 6, 5, 0} ;
    18         -static int minute_pins[] = {15, 14, 13, 12, 11, 10, 0} ;
    19         -static int second_pins[] = {16, 0} ;
           16  +static int ampm_pins[] = {5, 6, 0} ;
           17  +static int hour_pins[] = {11, 10, 9, 8, 7, 0} ;
           18  +static int minute_pins[] = {17, 16, 15, 14, 13, 12, 0} ;
           19  +static int second_pins[] = {18, 0} ;
    20     20   
    21     21   /*
    22     22    * We use a single blinking LED for seconds. By making it an RGB LED
    23     23    * and setting the ampm pins to the other two color pins in it, we can
    24     24    * change the color of the blink to indicate 24 hour mode, am, or pm.
    25     25    * Define AMPMRGB if that is the case.
    26     26    */
    27     27   //#define AMPMRGB
    28     28   
    29     29   // Define the delays on button actions
    30     30   #define DEBOUNCE	50	// debounce time
    31         -#define AUTO_DELAY	100	// Automatic counter
    32         -#define LONG_DELAY	250	// Delay befoer starting automatic counter
           31  +#define AUTO_DELAY	200	// Automatic counter
           32  +#define LONG_DELAY	300	// Delay befoer starting automatic counter
    33     33   
    34     34   // We want to use the internal pullup resistors if we can.
    35     35   #define INPUT_TYPE(down) (down == LOW ? INPUT_PULLUP : INPUT)
    36     36   
    37     37   /*
    38     38    * Now the structure used to drive the display.
    39         - * Tuples consisting of the pin arrays from above and a function to extract
    40         - * the displayed value from a time_t. Terminated by a pair of NULL pointers.
           39  + * Triples consisting of the pin arrays from above, a function to extract
           40  + * the displayed value from a time_t, and a function to increment the
           41  + * displayed value in a time_t.
           42  + * Terminated by a pair of NULL pointers.
    41     43    */
    42     44   typedef struct {
    43     45     int *pins ;			// The pin array for this display
    44     46     int (*fetch)(time_t) ;	// Function to fetch value from time_t
    45     47     void (*adjuster)(time_t) ;	// Adjust this value
    46     48   } Display ;
    47     49   
................................................................................
   186    188     }
   187    189   }
   188    190   
   189    191   /*
   190    192    * Routines for adjusting settings.
   191    193    * Each is called when the SET button is pressed to advance the selected
   192    194    * objects to the next state.
   193         - *
   194         - * Time settings always set the seconds back to 0 to avoid the clock
   195         - * advancing while we're setting it. To get the seconds "right", set minutes
   196         - * to the current minute, then advance it when your reference clock advances.
   197    195    */
   198    196   static void
   199    197   adjust_dow(time_t t) {
   200         -  setTime(hour(t), minute(t), 0, (day(t) % 7) + 1, month(t), year(t)) ;
          198  +  setTime(hour(t), minute(t), second(t), (day(t) % 7) + 1, month(t), year(t)) ;
   201    199   }
   202    200   
   203    201   // adjusting ampm adjust our display mode, not the time, and is saved to EEPROM
   204    202   static void
   205    203   adjust_ampm(time_t) {
   206    204     ampm = !ampm ;
   207    205     EEPROM.write(AMPM, ampm) ;
   208    206   }
   209    207   
   210    208   static void
   211    209   adjust_hour(time_t t) {
   212         -  setTime((hour(t) + 1) % 24, minute(t), 0, day(t), month(t), year(t)) ;
          210  +  setTime((hour(t) + 1) % 24, minute(t), second(t), day(t), month(t), year(t)) ;
   213    211   }
   214    212   
          213  +/*
          214  + * Minute resets seconds. Set the minute when your reference time changes
          215  + * to get seconds mostly right.
          216  + */
   215    217   static void
   216    218   adjust_minute(time_t t) {
   217    219     setTime(hour(t), (minute(t) + 1) % 60, 0, day(t), month(t), year(t)) ;
   218    220   }