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.000
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
Unified Diff Ignore Whitespace Patch
Changes to Arduino/Watch/Watch.ino.
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

/*
 * Sets of pins used for the LED displays.
 * These are LSB first, with a trailing 0 to indicate the last LED in the set.
 * Note that this means we can't drive an LED with pin 0. Use it for a switch.
 */
static int dow_pins[] = {4, 3, 2, 0} ;
static int ampm_pins[] = {18, 17, 0} ;
static int hour_pins[] = {9, 8, 7, 6, 5, 0} ;
static int minute_pins[] = {15, 14, 13, 12, 11, 10, 0} ;
static int second_pins[] = {16, 0} ;

/*
 * We use a single blinking LED for seconds. By making it an RGB LED
 * and setting the ampm pins to the other two color pins in it, we can
 * change the color of the blink to indicate 24 hour mode, am, or pm.
 * Define AMPMRGB if that is the case.
 */
//#define AMPMRGB

// Define the delays on button actions
#define DEBOUNCE	50	// debounce time
#define AUTO_DELAY	100	// Automatic counter
#define LONG_DELAY	250	// Delay befoer starting automatic counter

// We want to use the internal pullup resistors if we can.
#define INPUT_TYPE(down) (down == LOW ? INPUT_PULLUP : INPUT)

/*
 * Now the structure used to drive the display.
 * Tuples consisting of the pin arrays from above and a function to extract
 * the displayed value from a time_t. Terminated by a pair of NULL pointers.


 */
typedef struct {
  int *pins ;			// The pin array for this display
  int (*fetch)(time_t) ;	// Function to fetch value from time_t
  void (*adjuster)(time_t) ;	// Adjust this value
} Display ;








|
|
|
|











|
|






|
|
>
>







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

/*
 * Sets of pins used for the LED displays.
 * These are LSB first, with a trailing 0 to indicate the last LED in the set.
 * Note that this means we can't drive an LED with pin 0. Use it for a switch.
 */
static int dow_pins[] = {4, 3, 2, 0} ;
static int ampm_pins[] = {5, 6, 0} ;
static int hour_pins[] = {11, 10, 9, 8, 7, 0} ;
static int minute_pins[] = {17, 16, 15, 14, 13, 12, 0} ;
static int second_pins[] = {18, 0} ;

/*
 * We use a single blinking LED for seconds. By making it an RGB LED
 * and setting the ampm pins to the other two color pins in it, we can
 * change the color of the blink to indicate 24 hour mode, am, or pm.
 * Define AMPMRGB if that is the case.
 */
//#define AMPMRGB

// Define the delays on button actions
#define DEBOUNCE	50	// debounce time
#define AUTO_DELAY	200	// Automatic counter
#define LONG_DELAY	300	// Delay befoer starting automatic counter

// We want to use the internal pullup resistors if we can.
#define INPUT_TYPE(down) (down == LOW ? INPUT_PULLUP : INPUT)

/*
 * Now the structure used to drive the display.
 * Triples consisting of the pin arrays from above, a function to extract
 * the displayed value from a time_t, and a function to increment the
 * displayed value in a time_t.
 * Terminated by a pair of NULL pointers.
 */
typedef struct {
  int *pins ;			// The pin array for this display
  int (*fetch)(time_t) ;	// Function to fetch value from time_t
  void (*adjuster)(time_t) ;	// Adjust this value
} Display ;

186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214




215
216
217
218
  }
}

/*
 * Routines for adjusting settings.
 * Each is called when the SET button is pressed to advance the selected
 * objects to the next state.
 *
 * Time settings always set the seconds back to 0 to avoid the clock
 * advancing while we're setting it. To get the seconds "right", set minutes
 * to the current minute, then advance it when your reference clock advances.
 */
static void
adjust_dow(time_t t) {
  setTime(hour(t), minute(t), 0, (day(t) % 7) + 1, month(t), year(t)) ;
}

// adjusting ampm adjust our display mode, not the time, and is saved to EEPROM
static void
adjust_ampm(time_t) {
  ampm = !ampm ;
  EEPROM.write(AMPM, ampm) ;
}

static void
adjust_hour(time_t t) {
  setTime((hour(t) + 1) % 24, minute(t), 0, day(t), month(t), year(t)) ;
}





static void
adjust_minute(time_t t) {
  setTime(hour(t), (minute(t) + 1) % 60, 0, day(t), month(t), year(t)) ;
}







<
<
<
<



|











|


>
>
>
>




188
189
190
191
192
193
194




195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
  }
}

/*
 * Routines for adjusting settings.
 * Each is called when the SET button is pressed to advance the selected
 * objects to the next state.




 */
static void
adjust_dow(time_t t) {
  setTime(hour(t), minute(t), second(t), (day(t) % 7) + 1, month(t), year(t)) ;
}

// adjusting ampm adjust our display mode, not the time, and is saved to EEPROM
static void
adjust_ampm(time_t) {
  ampm = !ampm ;
  EEPROM.write(AMPM, ampm) ;
}

static void
adjust_hour(time_t t) {
  setTime((hour(t) + 1) % 24, minute(t), second(t), day(t), month(t), year(t)) ;
}

/*
 * Minute resets seconds. Set the minute when your reference time changes
 * to get seconds mostly right.
 */
static void
adjust_minute(time_t t) {
  setTime(hour(t), (minute(t) + 1) % 60, 0, day(t), month(t), year(t)) ;
}