/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-01 14:05:28 UTC
  • Revision ID: edam@waxworlds.org-20120101140528-ldqldo67nil1xf1s
added arduino.mk to the project

Show diffs side-by-side

added added

removed removed

35
35
   13 is at the outside.
36
36
 
37
37
 * if a longer hand (and a larger clock face) is desired, pin 4 can be
38
 
   used to indirectly drive a transistor which in turn drives several
39
 
   LEDs that turn on anf off in unison in the centre of the clock.
 
38
   used to indirectly drive (via a MOSFET) multiple LEDs which turn on
 
39
   and off in unison in the centre of the clock.
40
40
 
41
41
 * a button should be attached to pin 3 that grounds it when pressed.
42
42
 
43
 
 * A DS1307 remote clock is connected via I2C on analog pins 4 and 5.
44
 
 
45
43
Implementation details:
46
44
 
47
 
 * for a schematic, see ../project/propeller-clock.sch.
 
45
 * for a schematic, see project/propeller-clock.sch.
48
46
 
49
47
 * the timing of the drawing of the clock face is recalculated with
50
48
   every rotation of the propeller.
69
67
    - pressing the button increments the field currently being set
70
68
    - pressing and holding the button for a second cycles through the
71
69
      fields that can be set
72
 
    - pressing and holding the button for 5 seconds sets the time and
73
 
      exits "time set" mode
 
70
    - press and holding the button for 5 seconds to finish
74
71
 
75
72
******************************************************************************/
76
73
 
77
74
 
78
75
#include <Bounce.h>
79
 
#include <DS1307.h>
80
 
#include <Wire.h>
81
76
 
82
77
//_____________________________________________________________________________
83
78
//                                                                         data
160
155
}
161
156
 
162
157
 
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
158
// draw a segment for the test display
179
159
void drawNextSegment_test( bool reset )
180
160
{
184
164
        segment++;
185
165
 
186
166
        // turn on inside and outside LEDs
187
 
        ledOn( 0, true );
188
 
        ledOn( 9, true );
 
167
        digitalWrite( 4, HIGH );
 
168
        digitalWrite( 13, HIGH );
189
169
 
190
170
        // display segment number in binary across in the inside LEDs,
191
171
        // with the LED on pin 12 showing the least-significant bit
192
172
        for( int a = 0; a < 8; a++ )
193
 
                ledOn( 8 - a, ( segment >> a ) & 1 );
 
173
                digitalWrite( 12 - a, ( ( segment >> a ) & 1 )? HIGH : LOW );
194
174
}
195
175
 
196
176
 
197
177
// draw a segment for the time display
198
178
void drawNextSegment_time( bool reset )
199
179
{
200
 
        static int second = 0;
201
 
        static int segment = 0;
 
180
        static unsigned int second = 0;
 
181
        static unsigned int segment = 0;
202
182
 
203
183
        // handle display reset
204
184
        if( reset ) {
213
193
        bool draw_hour = !segment && second == time_hours;
214
194
 
215
195
        // 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 );
 
196
        digitalWrite( 13, HIGH );
 
197
        digitalWrite( 12, draw_tick || draw_minute );
 
198
        for( int a = 10; a <= 11; a++ )
 
199
                digitalWrite( a, draw_minute || draw_second );
 
200
        for( int a = 4; a <= 9; a++ )
 
201
                digitalWrite( 10, draw_minute | draw_second || draw_hour );
222
202
 
223
203
        // inc position
224
204
        if( ++segment >= NUM_SECOND_SEGMENTS ) {
324
304
        // set up mode-switch button on pin 3
325
305
        pinMode( 3, INPUT );
326
306
 
327
 
        // get the time from the real-time clock
328
 
        int rtc_data[ 7 ];
329
 
        RTC.get( rtc_data, true );
330
 
        time_hours = rtc_data[ DS1307_HR ];
331
 
        time_minutes = rtc_data[ DS1307_MIN ];
332
 
        time_seconds = rtc_data[ DS1307_SEC ];
333
 
 
334
307
        // serial comms
335
308
        Serial.begin( 9600 );
336
309
}