/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 00:08:14 UTC
  • Revision ID: edam@waxworlds.org-20120126000814-tcoazbkb84e0s1wl
abstracted turning leds on/off to cope with PNP-inverted pin 4 and fixed warnings

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
 
163
178
// draw a segment for the test display
164
179
void drawNextSegment_test( bool reset )
165
180
{
169
184
        segment++;
170
185
 
171
186
        // turn on inside and outside LEDs
172
 
        digitalWrite( 4, HIGH );
173
 
        digitalWrite( 13, HIGH );
 
187
        ledOn( 0, true );
 
188
        ledOn( 9, true );
174
189
 
175
190
        // display segment number in binary across in the inside LEDs,
176
191
        // with the LED on pin 12 showing the least-significant bit
177
192
        for( int a = 0; a < 8; a++ )
178
 
                digitalWrite( 12 - a, ( ( segment >> a ) & 1 )? HIGH : LOW );
 
193
                ledOn( 8 - a, ( segment >> a ) & 1 );
179
194
}
180
195
 
181
196
 
182
197
// draw a segment for the time display
183
198
void drawNextSegment_time( bool reset )
184
199
{
185
 
        static unsigned int second = 0;
186
 
        static unsigned int segment = 0;
 
200
        static int second = 0;
 
201
        static int segment = 0;
187
202
 
188
203
        // handle display reset
189
204
        if( reset ) {
198
213
        bool draw_hour = !segment && second == time_hours;
199
214
 
200
215
        // set the LEDs
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 );
 
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 );
207
222
 
208
223
        // inc position
209
224
        if( ++segment >= NUM_SECOND_SEGMENTS ) {