Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 5:46b14ed96df3
- Parent:
- 4:e2b18050c4d5
- Child:
- 6:5213e60b19c9
--- a/main.cpp Fri Dec 05 02:54:36 2014 +0000
+++ b/main.cpp Fri Feb 06 05:18:04 2015 +0000
@@ -64,14 +64,17 @@
PMOD_TYPE_5_HBRIDGE,
PMOD_TYPE_6_HBRIDGE
*/
- Ard2Pmod ard2pmod;
+
+ Ard2Pmod rtc; //instantiate Ard2Pmod class with default constructor
+
+ //default destructor call example
+ //rtc.~Ard2Pmod();
//can be used to wiggle lines for PMOD_TYPE_1_GPIO
//BusOut pmod_A(D10, D11, D12, D13);
//BusOut pmod_B(D4, D5, D6, D7);
//DS3231 rtc variables
-
//default for control and status registers,
//use bit masks in ds3231.h for desired operation
ds3231_cntl_stat_t rtc_control_status = {0,0};
@@ -80,57 +83,65 @@
time_t epoch_time;
- ard2pmod.set_cntl_stat_reg(rtc_control_status);
+ rtc.set_cntl_stat_reg(rtc_control_status);
+
+ uint8_t user_input;
- //get day from user
- get_user_input("\nPlease enter day of week, 1 for Sunday (1-7): ", 1,
- 7, &rtc_calendar.day);
-
- //get day of month from user
- get_user_input("\nPlease enter day of month (1-31): ", 1, 31,
- &rtc_calendar.date);
-
- //get month from user
- get_user_input("\nPlease enter the month, 1 for January (1-12): ", 1,
- 12, &rtc_calendar.month);
-
- //get year from user
- get_user_input("\nPlease enter the year (0-99): ",0, 99,
- &rtc_calendar.year);
-
- //Get time mode
- get_user_input("\nWhat time mode? 1 for 12hr 0 for 24hr: ", 0, 1,
- (uint8_t*) &rtc_time.mode);
+ get_user_input("\nDo you want to set the RTC time and calendar (1 for yes, 0 for no): ", 0,
+ 1, &user_input);
- if(rtc_time.mode)
+ if(user_input)
{
- //Get AM/PM status
- get_user_input("\nIs it AM or PM? 0 for AM 1 for PM: ", 0, 1,
- (uint8_t*) &rtc_time.am_pm);
- //Get hour from user
- get_user_input("\nPlease enter the hour (1-12): ", 1, 12,
- &rtc_time.hours);
- }
- else
- {
- //Get hour from user
- get_user_input("\nPlease enter the hour (0-23): ", 0, 23,
- &rtc_time.hours);
+ //get day from user
+ get_user_input("\nPlease enter day of week, 1 for Sunday (1-7): ", 1,
+ 7, &rtc_calendar.day);
+
+ //get day of month from user
+ get_user_input("\nPlease enter day of month (1-31): ", 1, 31,
+ &rtc_calendar.date);
+
+ //get month from user
+ get_user_input("\nPlease enter the month, 1 for January (1-12): ", 1,
+ 12, &rtc_calendar.month);
+
+ //get year from user
+ get_user_input("\nPlease enter the year (0-99): ",0, 99,
+ &rtc_calendar.year);
+
+ //Get time mode
+ get_user_input("\nWhat time mode? 1 for 12hr 0 for 24hr: ", 0, 1,
+ (uint8_t*) &rtc_time.mode);
+
+ if(rtc_time.mode)
+ {
+ //Get AM/PM status
+ get_user_input("\nIs it AM or PM? 0 for AM 1 for PM: ", 0, 1,
+ (uint8_t*) &rtc_time.am_pm);
+ //Get hour from user
+ get_user_input("\nPlease enter the hour (1-12): ", 1, 12,
+ &rtc_time.hours);
+ }
+ else
+ {
+ //Get hour from user
+ get_user_input("\nPlease enter the hour (0-23): ", 0, 23,
+ &rtc_time.hours);
+ }
+
+ //Get minutes from user
+ get_user_input("\nPlease enter the minute (0-59): ", 0, 59,
+ &rtc_time.minutes);
+
+ //Get seconds from user
+ get_user_input("\nPlease enter the second (0-59): ", 0, 59,
+ &rtc_time.seconds);
+
+ //Set the time
+ rtc.set_time(rtc_time);
+
+ //Set the calendar
+ rtc.set_calendar(rtc_calendar);
}
-
- //Get minutes from user
- get_user_input("\nPlease enter the minute (0-59): ", 0, 59,
- &rtc_time.minutes);
-
- //Get seconds from user
- get_user_input("\nPlease enter the second (0-59): ", 0, 59,
- &rtc_time.seconds);
-
- //Set the time
- ard2pmod.set_time(rtc_time);
-
- //Set the calendar
- ard2pmod.set_calendar(rtc_calendar);
char buffer[32];
@@ -140,7 +151,7 @@
term.printf("%c[H", ESC); //move cursor to Home
//new epoch time fx
- epoch_time = ard2pmod.get_epoch();
+ epoch_time = rtc.get_epoch();
term.printf("\nTime as seconds since January 1, 1970 = %d\n", epoch_time);
MAXREFDES72# Ard2Pmod Shield