/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-18 23:22:57 UTC
  • Revision ID: edam@waxworlds.org-20120118232257-a3323t3u7nd84zbd
updated led test and added real-time clock to the schematic

Show diffs side-by-side

added added

removed removed

160
160
}
161
161
 
162
162
 
163
 
// turn an led on/off
164
 
void ledOn( int num, bool on )
165
 
{
166
 
        if( num < 0 || num > 9 ) return;
167
 
 
168
 
        // convert to pin no.
169
 
        num += 4;
170
 
 
171
 
        // pin 4 needs to be inverted (it's driving a PNP)
172
 
        if( num == 4 ) on = !on;
173
 
 
174
 
        digitalWrite( num, on? HIGH : LOW );
175
 
}
176
 
 
177
 
 
178
163
// draw a segment for the test display
179
164
void drawNextSegment_test( bool reset )
180
165
{
184
169
        segment++;
185
170
 
186
171
        // turn on inside and outside LEDs
187
 
        ledOn( 0, true );
188
 
        ledOn( 9, true );
 
172
        digitalWrite( 4, HIGH );
 
173
        digitalWrite( 13, HIGH );
189
174
 
190
175
        // display segment number in binary across in the inside LEDs,
191
176
        // with the LED on pin 12 showing the least-significant bit
192
177
        for( int a = 0; a < 8; a++ )
193
 
                ledOn( 8 - a, ( segment >> a ) & 1 );
 
178
                digitalWrite( 12 - a, ( ( segment >> a ) & 1 )? HIGH : LOW );
194
179
}
195
180
 
196
181
 
197
182
// draw a segment for the time display
198
183
void drawNextSegment_time( bool reset )
199
184
{
200
 
        static int second = 0;
201
 
        static int segment = 0;
 
185
        static unsigned int second = 0;
 
186
        static unsigned int segment = 0;
202
187
 
203
188
        // handle display reset
204
189
        if( reset ) {
213
198
        bool draw_hour = !segment && second == time_hours;
214
199
 
215
200
        // set the LEDs
216
 
        ledOn( 9, true );
217
 
        ledOn( 8, draw_tick || draw_minute );
218
 
        for( int a = 6; a <= 7; a++ )
219
 
                ledOn( a, draw_minute || draw_second );
220
 
        for( int a = 0; a <= 5; a++ )
221
 
                ledOn( a, draw_minute || draw_second || draw_hour );
 
201
        digitalWrite( 13, HIGH );
 
202
        digitalWrite( 12, draw_tick || draw_minute );
 
203
        for( int a = 10; a <= 11; a++ )
 
204
                digitalWrite( a, draw_minute || draw_second );
 
205
        for( int a = 4; a <= 9; a++ )
 
206
                digitalWrite( 10, draw_minute | draw_second || draw_hour );
222
207
 
223
208
        // inc position
224
209
        if( ++segment >= NUM_SECOND_SEGMENTS ) {