/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-08 23:32:34 UTC
  • Revision ID: edam@waxworlds.org-20120208233234-4h5pzeetrz0vp91f
added phantom button press test and temporarily disabled pin 4 (that drives the PNP transistor)

Show diffs side-by-side

added added

removed removed

 
1
/* -*- mode: c++; compile-command: "BOARD=pro5v make"; -*- */
1
2
/*
2
3
 * propeller-clock.ino
3
4
 *
102
103
static bool inc_draw_mode = false;
103
104
 
104
105
// a bounce-managed button
105
 
static Bounce button( 3, 5 );
 
106
static Bounce button( 3, 50 );
106
107
 
107
108
// the time
108
109
static int time_hours = 0;
160
161
}
161
162
 
162
163
 
 
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
 
163
180
// draw a segment for the test display
164
181
void drawNextSegment_test( bool reset )
165
182
{
169
186
        segment++;
170
187
 
171
188
        // turn on inside and outside LEDs
172
 
        digitalWrite( 4, HIGH );
173
 
        digitalWrite( 13, HIGH );
 
189
        ledOn( 0, true );
 
190
        ledOn( 9, true );
174
191
 
175
192
        // display segment number in binary across in the inside LEDs,
176
193
        // with the LED on pin 12 showing the least-significant bit
177
194
        for( int a = 0; a < 8; a++ )
178
 
                digitalWrite( 12 - a, ( ( segment >> a ) & 1 )? HIGH : LOW );
 
195
                ledOn( 8 - a, ( segment >> a ) & 1 );
179
196
}
180
197
 
181
198
 
182
199
// draw a segment for the time display
183
200
void drawNextSegment_time( bool reset )
184
201
{
185
 
        static unsigned int second = 0;
186
 
        static unsigned int segment = 0;
 
202
        static int second = 0;
 
203
        static int segment = 0;
187
204
 
188
205
        // handle display reset
189
206
        if( reset ) {
198
215
        bool draw_hour = !segment && second == time_hours;
199
216
 
200
217
        // 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 );
 
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 );
207
224
 
208
225
        // inc position
209
226
        if( ++segment >= NUM_SECOND_SEGMENTS ) {
308
325
 
309
326
        // set up mode-switch button on pin 3
310
327
        pinMode( 3, INPUT );
 
328
        digitalWrite( 3, HIGH );
311
329
 
312
330
        // get the time from the real-time clock
313
331
        int rtc_data[ 7 ];