This sketch set an single alarm that will be active after one minute.
Dependencies: Hotboards_rtcc mbed
main.cpp@0:7c98016e3c5e, 2016-02-10 (annotated)
- Committer:
- Hotboards
- Date:
- Wed Feb 10 18:12:48 2016 +0000
- Revision:
- 0:7c98016e3c5e
first release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Hotboards | 0:7c98016e3c5e | 1 | |
Hotboards | 0:7c98016e3c5e | 2 | /* |
Hotboards | 0:7c98016e3c5e | 3 | Hotboards_rtcc Library - alarm |
Hotboards | 0:7c98016e3c5e | 4 | Demonstrates the use a MCP7941x clock calendar. The Hotboards_rtcc |
Hotboards | 0:7c98016e3c5e | 5 | library works with this microchip real time clock |
Hotboards | 0:7c98016e3c5e | 6 | (http://www.hotboards.org). |
Hotboards | 0:7c98016e3c5e | 7 | |
Hotboards | 0:7c98016e3c5e | 8 | This sketch set an single alarm that will be active |
Hotboards | 0:7c98016e3c5e | 9 | after one minute. |
Hotboards | 0:7c98016e3c5e | 10 | The circuit: |
Hotboards | 0:7c98016e3c5e | 11 | * VDD --> 3.3v |
Hotboards | 0:7c98016e3c5e | 12 | * GND --> GND |
Hotboards | 0:7c98016e3c5e | 13 | * SDA --> SDA |
Hotboards | 0:7c98016e3c5e | 14 | * SCL --> SCL |
Hotboards | 0:7c98016e3c5e | 15 | |
Hotboards | 0:7c98016e3c5e | 16 | */ |
Hotboards | 0:7c98016e3c5e | 17 | #include "mbed.h" |
Hotboards | 0:7c98016e3c5e | 18 | #include "Hotboards_rtcc.h" |
Hotboards | 0:7c98016e3c5e | 19 | |
Hotboards | 0:7c98016e3c5e | 20 | /* days of the week */ |
Hotboards | 0:7c98016e3c5e | 21 | const char *week[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; |
Hotboards | 0:7c98016e3c5e | 22 | /* months of the year */ |
Hotboards | 0:7c98016e3c5e | 23 | const char *months[] = {"JAN","FEB","MAR","APR","MAY","JUN", "JUL", "AUG","SEPT","OCT","NOV","DEC"}; |
Hotboards | 0:7c98016e3c5e | 24 | |
Hotboards | 0:7c98016e3c5e | 25 | /*serial port init*/ |
Hotboards | 0:7c98016e3c5e | 26 | Serial pc(USBTX,USBRX); |
Hotboards | 0:7c98016e3c5e | 27 | /*i2c instance delaration for use with the rtcc library*/ |
Hotboards | 0:7c98016e3c5e | 28 | I2C device(PB_9, PB_8); |
Hotboards | 0:7c98016e3c5e | 29 | /*lets declare and rtcc instance */ |
Hotboards | 0:7c98016e3c5e | 30 | Hotboards_rtcc rtcc(device); |
Hotboards | 0:7c98016e3c5e | 31 | |
Hotboards | 0:7c98016e3c5e | 32 | int main() |
Hotboards | 0:7c98016e3c5e | 33 | { |
Hotboards | 0:7c98016e3c5e | 34 | /*i2c bus clock set to 100khz*/ |
Hotboards | 0:7c98016e3c5e | 35 | device.frequency(100000); |
Hotboards | 0:7c98016e3c5e | 36 | /* init the rtcc, just enable the clock if not already enable */ |
Hotboards | 0:7c98016e3c5e | 37 | rtcc.begin(); |
Hotboards | 0:7c98016e3c5e | 38 | /* set the time when is compiled*/ |
Hotboards | 0:7c98016e3c5e | 39 | DateTime time( __DATE__, __TIME__); |
Hotboards | 0:7c98016e3c5e | 40 | rtcc.adjust(time); |
Hotboards | 0:7c98016e3c5e | 41 | |
Hotboards | 0:7c98016e3c5e | 42 | /* Set an alarm after one minute */ |
Hotboards | 0:7c98016e3c5e | 43 | DateTime alarm = time + TimeSpan( 0, 0, 1, 0 ); |
Hotboards | 0:7c98016e3c5e | 44 | rtcc.setAlarm( alarm ); |
Hotboards | 0:7c98016e3c5e | 45 | /* enable the alarm */ |
Hotboards | 0:7c98016e3c5e | 46 | rtcc.turnOnAlarm( ); |
Hotboards | 0:7c98016e3c5e | 47 | |
Hotboards | 0:7c98016e3c5e | 48 | printf("The alarm will be active in one minute \n"); |
Hotboards | 0:7c98016e3c5e | 49 | |
Hotboards | 0:7c98016e3c5e | 50 | while(1) |
Hotboards | 0:7c98016e3c5e | 51 | { |
Hotboards | 0:7c98016e3c5e | 52 | /* is the alarm active?? */ |
Hotboards | 0:7c98016e3c5e | 53 | if( rtcc.getAlarmStatus( ) == 1 ) |
Hotboards | 0:7c98016e3c5e | 54 | { |
Hotboards | 0:7c98016e3c5e | 55 | /* clear the alarm */ |
Hotboards | 0:7c98016e3c5e | 56 | rtcc.clearAlarm( ); |
Hotboards | 0:7c98016e3c5e | 57 | /* display the time */ |
Hotboards | 0:7c98016e3c5e | 58 | DateTime time = rtcc.now( ); |
Hotboards | 0:7c98016e3c5e | 59 | printf( "Alarm active at: Time- %d:%d:%d Date- %s/ %d/ %s/ %d\n",time.hour( ),time.minute( ),time.second( ),week[time.dayOfTheWeek( )],time.day( ),months[time.month( )],time.year()); |
Hotboards | 0:7c98016e3c5e | 60 | } |
Hotboards | 0:7c98016e3c5e | 61 | } |
Hotboards | 0:7c98016e3c5e | 62 | } |