/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:25:08 UTC
  • Revision ID: edam@waxworlds.org-20120223002508-u4lghz4rb7vbr4ou
only one led comes on

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