/elec/propeller-clock

To get this branch, use:
bzr branch http://bzr.ed.am/elec/propeller-clock

« back to all changes in this revision

Viewing changes to src/propeller-clock.ino

  • Committer: edam
  • Date: 2012-02-23 00:26:32 UTC
  • Revision ID: edam@waxworlds.org-20120223002632-kkwrdwijfmv45f0j
conrtol segment number from one place and reverse the order the segments are drawn (backwards clock!)

Show diffs side-by-side

added added

removed removed

 
1
/* -*- mode: c++; compile-command: "BOARD=pro5v make"; -*- */
1
2
/*
2
3
 * propeller-clock.ino
3
4
 *
102
103
static bool inc_draw_mode = false;
103
104
 
104
105
// a bounce-managed button
105
 
static Bounce button( 3, 5 );
 
106
static Bounce button( 3, 50 );
106
107
 
107
108
// the time
108
109
static int time_hours = 0;
114
115
#define NUM_SECOND_SEGMENTS 5
115
116
#define NUM_SEGMENTS ( 60 * NUM_SECOND_SEGMENTS )
116
117
 
 
118
// clock direction
 
119
#define CLOCK_FORWARD 0
 
120
 
117
121
//_____________________________________________________________________________
118
122
//                                                                         code
119
123
 
169
173
        num += 4;
170
174
 
171
175
        // pin 4 needs to be inverted (it's driving a PNP)
172
 
        if( num == 4 ) on = !on;
 
176
        // NOTE: PIN 4 TEMPORARILY DISABLED
 
177
//      if( num == 4 ) on = true;
 
178
if( num == 4 ) on = !on;
173
179
 
174
180
        digitalWrite( num, on? HIGH : LOW );
175
181
}
176
182
 
177
183
 
178
184
// draw a segment for the test display
179
 
void drawNextSegment_test( bool reset )
 
185
void drawNextSegment_test( int segment )
180
186
{
181
 
        // keep track of segment
182
 
        static unsigned int segment = 0;
183
 
        if( reset ) segment = 0;
184
 
        segment++;
185
 
 
186
187
        // turn on inside and outside LEDs
187
 
        ledOn( 0, true );
188
188
        ledOn( 9, true );
189
189
 
190
190
        // display segment number in binary across in the inside LEDs,
191
191
        // with the LED on pin 12 showing the least-significant bit
192
 
        for( int a = 0; a < 8; a++ )
 
192
        for( int a = 0; a < 9; a++ )
193
193
                ledOn( 8 - a, ( segment >> a ) & 1 );
194
194
}
195
195
 
196
196
 
197
197
// draw a segment for the time display
198
 
void drawNextSegment_time( bool reset )
 
198
void drawNextSegment_time( int segment )
199
199
{
200
 
        static int second = 0;
201
 
        static int segment = 0;
202
 
 
203
 
        // handle display reset
204
 
        if( reset ) {
205
 
                second = 0;
206
 
                segment = 0;
207
 
        }
 
200
        int second = segment / NUM_SECOND_SEGMENTS;
 
201
        int second_segment = segment % NUM_SECOND_SEGMENTS;
208
202
 
209
203
        // what needs to be drawn?
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;
 
204
        bool draw_tick = !second_segment && second % 5 == 0;
 
205
        bool draw_second = !second_segment && second == time_seconds;
 
206
        bool draw_minute = !second_segment && second == time_minutes;
 
207
        bool draw_hour = !second_segment && second == time_hours;
214
208
 
215
209
        // set the LEDs
216
210
        ledOn( 9, true );
219
213
                ledOn( a, draw_minute || draw_second );
220
214
        for( int a = 0; a <= 5; a++ )
221
215
                ledOn( a, draw_minute || draw_second || draw_hour );
222
 
 
223
 
        // inc position
224
 
        if( ++segment >= NUM_SECOND_SEGMENTS ) {
225
 
                segment = 0;
226
 
                second++;
227
 
        }
228
216
}
229
217
 
230
218
 
233
221
{
234
222
        static int draw_mode = 0;
235
223
 
 
224
        // keep track of segment
 
225
#if CLOCK_FORWARD
 
226
        static int segment = 0;
 
227
        if( reset ) segment = 0;
 
228
#else
 
229
        static int segment = NUM_SEGMENTS - 1;
 
230
        if( reset ) segment = NUM_SEGMENTS - 1;
 
231
#endif
 
232
 
236
233
        // handle mode switch requests
237
234
        if( reset && inc_draw_mode ) {
238
235
                inc_draw_mode = false;
243
240
 
244
241
        // draw the segment
245
242
        switch( draw_mode ) {
246
 
        case 0: drawNextSegment_test( reset ); break;
247
 
        case 1: drawNextSegment_time( reset ); break;
 
243
        case 0: drawNextSegment_test( segment ); break;
 
244
        case 1: drawNextSegment_time( segment ); break;
248
245
        }
 
246
 
 
247
#if CLOCK_FORWARD
 
248
        segment++;
 
249
#else
 
250
        segment--;
 
251
#endif
249
252
}
250
253
 
251
254
 
323
326
 
324
327
        // set up mode-switch button on pin 3
325
328
        pinMode( 3, INPUT );
 
329
        digitalWrite( 3, HIGH );
326
330
 
327
331
        // get the time from the real-time clock
328
332
        int rtc_data[ 7 ];