/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-14 17:31:34 UTC
  • Revision ID: edam@waxworlds.org-20120114173134-5zoqjn0upzpb4ufa
added led-test subproject

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;
161
160
}
162
161
 
163
162
 
164
 
// turn an led on/off
165
 
void ledOn( int num, bool on )
166
 
{
167
 
        if( num < 0 || num > 9 ) return;
168
 
 
169
 
        // convert to pin no.
170
 
        num += 4;
171
 
 
172
 
        // pin 4 needs to be inverted (it's driving a PNP)
173
 
        // NOTE: PIN 4 TEMPORARILY DISABLED
174
 
        if( num == 4 ) on = true; //!on
175
 
 
176
 
        digitalWrite( num, on? HIGH : LOW );
177
 
}
178
 
 
179
 
 
180
163
// draw a segment for the test display
181
164
void drawNextSegment_test( bool reset )
182
165
{
186
169
        segment++;
187
170
 
188
171
        // turn on inside and outside LEDs
189
 
        ledOn( 0, true );
190
 
        ledOn( 9, true );
 
172
        digitalWrite( 4, HIGH );
 
173
        digitalWrite( 13, HIGH );
191
174
 
192
175
        // display segment number in binary across in the inside LEDs,
193
176
        // with the LED on pin 12 showing the least-significant bit
194
177
        for( int a = 0; a < 8; a++ )
195
 
                ledOn( 8 - a, ( segment >> a ) & 1 );
 
178
                digitalWrite( 12 - a, ( ( segment >> a ) & 1 )? HIGH : LOW );
196
179
}
197
180
 
198
181
 
199
182
// draw a segment for the time display
200
183
void drawNextSegment_time( bool reset )
201
184
{
202
 
        static int second = 0;
203
 
        static int segment = 0;
 
185
        static unsigned int second = 0;
 
186
        static unsigned int segment = 0;
204
187
 
205
188
        // handle display reset
206
189
        if( reset ) {
215
198
        bool draw_hour = !segment && second == time_hours;
216
199
 
217
200
        // set the LEDs
218
 
        ledOn( 9, true );
219
 
        ledOn( 8, draw_tick || draw_minute );
220
 
        for( int a = 6; a <= 7; a++ )
221
 
                ledOn( a, draw_minute || draw_second );
222
 
        for( int a = 0; a <= 5; a++ )
223
 
                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 );
224
207
 
225
208
        // inc position
226
209
        if( ++segment >= NUM_SECOND_SEGMENTS ) {
325
308
 
326
309
        // set up mode-switch button on pin 3
327
310
        pinMode( 3, INPUT );
328
 
        digitalWrite( 3, HIGH );
329
311
 
330
312
        // get the time from the real-time clock
331
313
        int rtc_data[ 7 ];