/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-01-26 23:49:09 UTC
  • Revision ID: edam@waxworlds.org-20120126234909-2sk9o3fr9idt6yd4
updated notes and scematic (adding capacitor+resistor and diode)

Show diffs side-by-side

added added

removed removed

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