/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
1
/*
2
 
 * propeller-clock.pde
 
2
 * propeller-clock.ino
3
3
 *
4
 
 * Copyright (C) 2011 Tim Marston <edam@waxworlds.org>
 
4
 * Copyright (C) 2011 Tim Marston <tim@ed.am> and Dan Marston.
5
5
 *
6
6
 * This file is part of propeller-clock (hereafter referred to as "this
7
 
 * program"). See http://ed.am/software/arduino/propeller-clock for more
 
7
 * program"). See http://ed.am/dev/software/arduino/propeller-clock for more
8
8
 * information.
9
9
 *
10
10
 * This program is free software: you can redistribute it and/or modify
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 (via a MOSFET) multiple LEDs which turn on
39
 
   and off in unison in the centre of the clock.
 
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.
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
 
43
45
Implementation details:
44
46
 
45
 
 * for a schematic, see project/propeller-clock.sch.
 
47
 * for a schematic, see ../project/propeller-clock.sch.
46
48
 
47
49
 * the timing of the drawing of the clock face is recalculated with
48
50
   every rotation of the propeller.
67
69
    - pressing the button increments the field currently being set
68
70
    - pressing and holding the button for a second cycles through the
69
71
      fields that can be set
70
 
    - press and holding the button for 5 seconds to finish
 
72
    - pressing and holding the button for 5 seconds sets the time and
 
73
      exits "time set" mode
71
74
 
72
75
******************************************************************************/
73
76
 
74
77
 
75
78
#include <Bounce.h>
 
79
#include <DS1307.h>
 
80
#include <Wire.h>
76
81
 
77
82
//_____________________________________________________________________________
78
83
//                                                                         data
189
194
        // what needs to be drawn?
190
195
        bool draw_tick = !segment && second % 5 == 0;
191
196
        bool draw_second = !segment && second == time_seconds;
192
 
        bool draw_minute = !segment && second == time_minute;
193
 
        bool draw_hour = !segment && second == time_hour;
 
197
        bool draw_minute = !segment && second == time_minutes;
 
198
        bool draw_hour = !segment && second == time_hours;
194
199
 
195
200
        // set the LEDs
196
201
        digitalWrite( 13, HIGH );
304
309
        // set up mode-switch button on pin 3
305
310
        pinMode( 3, INPUT );
306
311
 
 
312
        // get the time from the real-time clock
 
313
        int rtc_data[ 7 ];
 
314
        RTC.get( rtc_data, true );
 
315
        time_hours = rtc_data[ DS1307_HR ];
 
316
        time_minutes = rtc_data[ DS1307_MIN ];
 
317
        time_seconds = rtc_data[ DS1307_SEC ];
 
318
 
307
319
        // serial comms
308
320
        Serial.begin( 9600 );
309
321
}