103
102
static bool inc_draw_mode = false;
105
104
// a bounce-managed button
106
static Bounce button( 3, 50 );
105
static Bounce button( 3, 5 );
109
108
static int time_hours = 0;
115
114
#define NUM_SECOND_SEGMENTS 5
116
115
#define NUM_SEGMENTS ( 60 * NUM_SECOND_SEGMENTS )
118
// clock draw direction
119
#define CLOCK_FORWARD 0
121
// rotate display (in segments)
122
#define CLOCK_SHIFT ( 58 * NUM_SECOND_SEGMENTS - 1 )
124
117
//_____________________________________________________________________________
185
178
// draw a segment for the test display
186
void drawNextSegment_test( int segment )
179
void drawNextSegment_test( bool reset )
188
// turn on outside LEDs
181
// keep track of segment
182
static unsigned int segment = 0;
183
if( reset ) segment = 0;
186
// turn on inside and outside LEDs
189
188
ledOn( 9, true );
191
190
// display segment number in binary across in the inside LEDs,
192
191
// with the LED on pin 12 showing the least-significant bit
193
for( int a = 0; a < 9; a++ )
192
for( int a = 0; a < 8; a++ )
194
193
ledOn( 8 - a, ( segment >> a ) & 1 );
198
197
// draw a segment for the time display
199
void drawNextSegment_time( int segment )
198
void drawNextSegment_time( bool reset )
201
int second = segment / NUM_SECOND_SEGMENTS;
202
int second_segment = segment % NUM_SECOND_SEGMENTS;
200
static int second = 0;
201
static int segment = 0;
203
// handle display reset
204
209
// what needs to be drawn?
205
bool draw_tick = ( !second_segment && second % 5 == 0 && second ) ||
206
( second == 0 && second_segment == 1 ) ||
207
( second == 59 && second_segment == NUM_SECOND_SEGMENTS - 1 );
208
bool draw_second = !second_segment && second == time_seconds;
209
bool draw_minute = !second_segment && second == time_minutes;
210
bool draw_hour = segment == time_hours * 5 * NUM_SECOND_SEGMENTS +
211
( 5 * NUM_SECOND_SEGMENTS * time_minutes / 60 );
210
bool draw_tick = !segment && second % 5 == 0;
211
bool draw_second = !segment && second == time_seconds;
212
bool draw_minute = !segment && second == time_minutes;
213
bool draw_hour = !segment && second == time_hours;
214
216
ledOn( 9, true );
215
ledOn( 8, draw_tick || draw_second );
217
ledOn( 8, draw_tick || draw_minute );
216
218
for( int a = 6; a <= 7; a++ )
217
219
ledOn( a, draw_minute || draw_second );
218
220
for( int a = 0; a <= 5; a++ )
219
221
ledOn( a, draw_minute || draw_second || draw_hour );
224
if( ++segment >= NUM_SECOND_SEGMENTS ) {
226
234
static int draw_mode = 0;
228
// keep track of segment
230
static int segment = ( NUM_SEGMENTS - CLOCK_SHIFT ) % NUM_SEGMENTS;
231
if( reset ) segment = ( NUM_SEGMENTS - CLOCK_SHIFT ) % NUM_SEGMENTS;
233
static int segment = NUM_SEGMENTS - 1 - CLOCK_SHIFT;
234
if( reset ) segment = NUM_SEGMENTS - 1 - CLOCK_SHIFT;
237
236
// handle mode switch requests
238
237
if( reset && inc_draw_mode ) {
239
238
inc_draw_mode = false;
245
244
// draw the segment
246
245
switch( draw_mode ) {
247
case 0: drawNextSegment_test( segment ); break;
248
case 1: drawNextSegment_time( segment ); break;
246
case 0: drawNextSegment_test( reset ); break;
247
case 1: drawNextSegment_time( reset ); break;
252
if( ++segment >= NUM_SEGMENTS ) segment = 0;
254
if( --segment < 0 ) segment = NUM_SEGMENTS - 1;