/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

115
115
#define NUM_SECOND_SEGMENTS 5
116
116
#define NUM_SEGMENTS ( 60 * NUM_SECOND_SEGMENTS )
117
117
 
 
118
// clock direction
 
119
#define CLOCK_FORWARD 0
 
120
 
118
121
//_____________________________________________________________________________
119
122
//                                                                         code
120
123
 
171
174
 
172
175
        // pin 4 needs to be inverted (it's driving a PNP)
173
176
        // NOTE: PIN 4 TEMPORARILY DISABLED
174
 
        if( num == 4 ) on = true; //!on
 
177
//      if( num == 4 ) on = true;
 
178
if( num == 4 ) on = !on;
175
179
 
176
180
        digitalWrite( num, on? HIGH : LOW );
177
181
}
178
182
 
179
183
 
180
184
// draw a segment for the test display
181
 
void drawNextSegment_test( bool reset )
 
185
void drawNextSegment_test( int segment )
182
186
{
183
 
        // keep track of segment
184
 
        static unsigned int segment = 0;
185
 
        if( reset ) segment = 0;
186
 
        segment++;
187
 
 
188
187
        // turn on inside and outside LEDs
189
 
        ledOn( 0, true );
190
188
        ledOn( 9, true );
191
189
 
192
190
        // display segment number in binary across in the inside LEDs,
193
191
        // with the LED on pin 12 showing the least-significant bit
194
 
        for( int a = 0; a < 8; a++ )
 
192
        for( int a = 0; a < 9; a++ )
195
193
                ledOn( 8 - a, ( segment >> a ) & 1 );
196
194
}
197
195
 
198
196
 
199
197
// draw a segment for the time display
200
 
void drawNextSegment_time( bool reset )
 
198
void drawNextSegment_time( int segment )
201
199
{
202
 
        static int second = 0;
203
 
        static int segment = 0;
204
 
 
205
 
        // handle display reset
206
 
        if( reset ) {
207
 
                second = 0;
208
 
                segment = 0;
209
 
        }
 
200
        int second = segment / NUM_SECOND_SEGMENTS;
 
201
        int second_segment = segment % NUM_SECOND_SEGMENTS;
210
202
 
211
203
        // what needs to be drawn?
212
 
        bool draw_tick = !segment && second % 5 == 0;
213
 
        bool draw_second = !segment && second == time_seconds;
214
 
        bool draw_minute = !segment && second == time_minutes;
215
 
        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;
216
208
 
217
209
        // set the LEDs
218
210
        ledOn( 9, true );
221
213
                ledOn( a, draw_minute || draw_second );
222
214
        for( int a = 0; a <= 5; a++ )
223
215
                ledOn( a, draw_minute || draw_second || draw_hour );
224
 
 
225
 
        // inc position
226
 
        if( ++segment >= NUM_SECOND_SEGMENTS ) {
227
 
                segment = 0;
228
 
                second++;
229
 
        }
230
216
}
231
217
 
232
218
 
235
221
{
236
222
        static int draw_mode = 0;
237
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
 
238
233
        // handle mode switch requests
239
234
        if( reset && inc_draw_mode ) {
240
235
                inc_draw_mode = false;
245
240
 
246
241
        // draw the segment
247
242
        switch( draw_mode ) {
248
 
        case 0: drawNextSegment_test( reset ); break;
249
 
        case 1: drawNextSegment_time( reset ); break;
 
243
        case 0: drawNextSegment_test( segment ); break;
 
244
        case 1: drawNextSegment_time( segment ); break;
250
245
        }
 
246
 
 
247
#if CLOCK_FORWARD
 
248
        segment++;
 
249
#else
 
250
        segment--;
 
251
#endif
251
252
}
252
253
 
253
254