Skip to content

Commit d9281f5

Browse files
committed
Standardize WDT/RTC examples
Fix low power examples
1 parent 0cab3f9 commit d9281f5

File tree

7 files changed

+129
-113
lines changed

7 files changed

+129
-113
lines changed

libraries/RTC/examples/Example1_Get_Time/Example1_Get_Time.ino

+15-15
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Created: Septempter 27th, 2019
44
55
This example demonstrates how to initialize and read from the on-board RTC.
6-
6+
77
Most SparkFun Artemis boards have the necessary external 32kHz crystal to
88
enable the RTC. If you are using the Artemis module bare you will either
99
need an external 32kHz xtal or use the internal LFRC. Read the datasheet
@@ -12,7 +12,7 @@
1212
This example is based on the Ambiq SDK EVB2 RTC example.
1313
*/
1414

15-
/*
15+
/*
1616
// This file is subject to the terms and conditions defined in
1717
// file 'LICENSE.md', which is part of this source code package.
1818
*/
@@ -25,28 +25,28 @@ void setup()
2525
Serial.println("SparkFun RTC Example");
2626

2727
// Easily set RTC using the system __DATE__ and __TIME__ macros from compiler
28-
RTC.setToCompilerTime();
28+
rtc.setToCompilerTime();
2929

30-
// // Manually set RTC date and time
31-
// RTC.setTime(0, 50, 59, 12, 3, 6, 20); // 12:59:50.000, June 3rd, 2020 (hund, ss, mm, hh, dd, mm, yy)
30+
// Manually set RTC date and time
31+
// rtc.setTime(0, 50, 59, 12, 3, 6, 20); // 12:59:50.000, June 3rd, 2020 (hund, ss, mm, hh, dd, mm, yy)
3232
}
3333

3434
void loop()
3535
{
36-
RTC.getTime();
36+
rtc.getTime();
3737

3838
Serial.printf("It is now ");
39-
Serial.printf("%d:", RTC.hour);
40-
Serial.printf("%02d:", RTC.minute);
41-
Serial.printf("%02d.", RTC.seconds);
42-
Serial.printf("%02d", RTC.hundredths);
39+
Serial.printf("%d:", rtc.hour);
40+
Serial.printf("%02d:", rtc.minute);
41+
Serial.printf("%02d.", rtc.seconds);
42+
Serial.printf("%02d", rtc.hundredths);
4343

44-
Serial.printf(" %02d/", RTC.month);
45-
Serial.printf("%02d/", RTC.dayOfMonth);
46-
Serial.printf("%02d", RTC.year);
44+
Serial.printf(" %02d/", rtc.month);
45+
Serial.printf("%02d/", rtc.dayOfMonth);
46+
Serial.printf("%02d", rtc.year);
4747

48-
Serial.printf(" Day of week: %d =", RTC.weekday);
49-
Serial.printf(" %s", RTC.textWeekday);
48+
Serial.printf(" Day of week: %d =", rtc.weekday);
49+
Serial.printf(" %s", rtc.textWeekday);
5050

5151
Serial.println();
5252

libraries/RTC/examples/Example2_Set_Alarms/Example2_Set_Alarms.ino

+17-19
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ void setup()
2828
Serial.println("SparkFun RTC Set Alarm Example");
2929

3030
// // Easily set RTC using the system __DATE__ and __TIME__ macros from compiler
31-
// RTC.setToCompilerTime();
31+
// rtc.setToCompilerTime();
3232

3333
// Manually set RTC date and time
34-
RTC.setTime(0, 50, 59, 12, 3, 6, 20); // 12:59:50.000, June 3rd, 2020 (hund, ss, mm, hh, dd, mm, yy)
34+
rtc.setTime(0, 50, 59, 12, 3, 6, 20); // 12:59:50.000, June 3rd, 2020 (hund, ss, mm, hh, dd, mm, yy)
3535

3636
// Set the RTC's alarm
37-
RTC.setAlarm(0, 0, 0, 13, 3, 6); // 13:00:00.000, June 3rd (hund, ss, mm, hh, dd, mm). Note: No year alarm register
37+
rtc.setAlarm(0, 0, 0, 13, 3, 6); // 13:00:00.000, June 3rd (hund, ss, mm, hh, dd, mm). Note: No year alarm register
3838

3939
// Set the RTC alarm mode
4040
/*
@@ -47,8 +47,8 @@ void setup()
4747
6: Alarm match every minute (hundredths, seconds)
4848
7: Alarm match every second (hundredths)
4949
*/
50-
RTC.setAlarmMode(6); // Set the RTC alarm to match on minutes rollover
51-
RTC.attachInterrupt(); // Attach RTC alarm interrupt
50+
rtc.setAlarmMode(6); // Set the RTC alarm to match on minutes rollover
51+
rtc.attachInterrupt(); // Attach RTC alarm interrupt
5252

5353
// Print the RTC's alarm date and time
5454
Serial.print("Next alarm: "); printAlarm();
@@ -77,31 +77,29 @@ void loop()
7777
// Print the RTC's current date and time
7878
void printDateTime()
7979
{
80-
RTC.getTime();
81-
char dateTimeBuffer[25];
82-
sprintf(dateTimeBuffer, "20%02d-%02d-%02d %02d:%02d:%02d.%03d",
83-
RTC.year, RTC.month, RTC.dayOfMonth,
84-
RTC.hour, RTC.minute, RTC.seconds, RTC.hundredths);
85-
Serial.println(dateTimeBuffer);
80+
rtc.getTime();
81+
Serial.printf("20%02d-%02d-%02d %02d:%02d:%02d.%03d\n",
82+
rtc.year, rtc.month, rtc.dayOfMonth,
83+
rtc.hour, rtc.minute, rtc.seconds, rtc.hundredths);
8684
}
8785

8886
// Print the RTC's alarm
8987
void printAlarm()
9088
{
91-
RTC.getAlarm();
92-
char alarmBuffer[25];
93-
sprintf(alarmBuffer, "2020-%02d-%02d %02d:%02d:%02d.%03d",
94-
RTC.alarmMonth, RTC.alarmDayOfMonth,
95-
RTC.alarmHour, RTC.alarmMinute,
96-
RTC.alarmSeconds, RTC.alarmHundredths);
97-
Serial.println(alarmBuffer);
89+
rtc.getAlarm();
90+
91+
Serial.printf("2020-%02d-%02d %02d:%02d:%02d.%03d\n",
92+
rtc.alarmMonth, rtc.alarmDayOfMonth,
93+
rtc.alarmHour, rtc.alarmMinute,
94+
rtc.alarmSeconds, rtc.alarmHundredths);
95+
Serial.println();
9896
}
9997

10098
// Interrupt handler for the RTC
10199
extern "C" void am_rtc_isr(void)
102100
{
103101
// Clear the RTC alarm interrupt.
104-
am_hal_rtc_int_clear(AM_HAL_RTC_INT_ALM);
102+
rtc.clearInterrupt();
105103

106104
// Set alarm flag
107105
alarmFlag = true;

libraries/RTC/examples/Example3_Test_RTC/Example3_Test_RTC.ino

+9-9
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ void setup()
2121
Serial.println("Artemis RTC Testing");
2222

2323
// Manually set RTC date and time to the start of 2020 so that RTC contains valid times
24-
RTC.setTime(0, 59, 59, 23, 1, 1, 20); // Set to 1 second before midnight Jan 1
24+
rtc.setTime(0, 59, 59, 23, 1, 1, 20); // Set to 1 second before midnight Jan 1
2525
}
2626

2727
void loop()
2828
{
29-
RTC.setTime(99, 59, 59, 23, RTC.dayOfMonth, RTC.month, RTC.year); // Manually set RTC 1/100th of a second from the next day
30-
previousDay = RTC.weekday;
29+
rtc.setTime(99, 59, 59, 23, rtc.dayOfMonth, rtc.month, rtc.year); // Manually set RTC 1/100th of a second from the next day
30+
previousDay = rtc.weekday;
3131
delay(11); //Allow us to roll from midnight the night before to the new day
3232

3333
printArtemisTime();
@@ -38,8 +38,8 @@ void printArtemisTime()
3838
char buf[50];
3939
char weekdayBuf[4];
4040

41-
RTC.getTime();
42-
int i = RTC.weekday + 1;
41+
rtc.getTime();
42+
int i = rtc.weekday + 1;
4343
switch (i)
4444
{
4545
case (1):
@@ -69,15 +69,15 @@ void printArtemisTime()
6969
break;
7070
}
7171

72-
sprintf(buf, "%02d-%02d-%02d (%s) %02d:%02d:%02d.%02d", RTC.year, RTC.month, RTC.dayOfMonth, weekdayBuf, RTC.hour, RTC.minute, RTC.seconds, RTC.hundredths);
72+
sprintf(buf, "%02d-%02d-%02d (%s) %02d:%02d:%02d.%02d", rtc.year, rtc.month, rtc.dayOfMonth, weekdayBuf, rtc.hour, rtc.minute, rtc.seconds, rtc.hundredths);
7373
Serial.print(buf);
7474

7575
//Move the previous day forward one day and make sure it matches today
76-
if ((previousDay + 1) % 7 != RTC.weekday)
76+
if ((previousDay + 1) % 7 != rtc.weekday)
7777
{
78-
Serial.printf(" Error! previousDay: %d today: %d\n", previousDay, RTC.weekday);
78+
Serial.printf(" Error! previousDay: %d today: %d\n", previousDay, rtc.weekday);
7979
while (1){};
8080
}
8181

8282
Serial.println();
83-
}
83+
}

libraries/RTC/examples/Example4_Set_Epoch/Example4_Set_Epoch.ino

+7-8
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ void setup()
1818
Serial.println("SparkFun RTC Set UNIX Epoch Time Example");
1919

2020
// Set the RTC time using UNIX Epoch time
21-
RTC.setEpoch(1591185600); // E.g. 12:00:00, June 3rd, 2020
21+
rtc.setEpoch(1591185600); // E.g. 12:00:00, June 3rd, 2020
2222
}
2323

2424
void loop()
2525
{
2626
// Print UNIX Epoch timestamp
27-
Serial.print("Epoch time: "); Serial.println(RTC.getEpoch());
27+
Serial.print("Epoch time: "); Serial.println(rtc.getEpoch());
2828

2929
// Print RTC's date and time
3030
Serial.print("Timestamp: "); printDateTime();
@@ -35,10 +35,9 @@ void loop()
3535
// Print the RTC's current date and time
3636
void printDateTime()
3737
{
38-
RTC.getTime();
39-
char dateTime[20];
40-
sprintf(dateTime, "20%02d-%02d-%02d %02d:%02d:%02d",
41-
RTC.year, RTC.month, RTC.dayOfMonth,
42-
RTC.hour, RTC.minute, RTC.seconds);
43-
Serial.println(dateTime);
38+
rtc.getTime();
39+
Serial.printf("20%02d-%02d-%02d %02d:%02d:%02d\n",
40+
rtc.year, rtc.month, rtc.dayOfMonth,
41+
rtc.hour, rtc.minute, rtc.seconds);
42+
Serial.println();
4443
}

libraries/RTC/examples/Example5_Rolling_Alarms/Example5_Rolling_Alarms.ino

+30-32
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
Author: Adam Garbo and Nathan Seidle
33
Created: June 3rdrd, 2020
44
5-
This example demonstrates how to read and set rolling RTC alarms. Each time
6-
the alarm triggers, a user-specified additional amount of time (seconds,
7-
minutes or hours) can be added to create a rolling RTC alarm. Second,
5+
This example demonstrates how to read and set rolling RTC alarms. Each time
6+
the alarm triggers, a user-specified additional amount of time (seconds,
7+
minutes or hours) can be added to create a rolling RTC alarm. Second,
88
minute and hour rollovers are handled using modulo calculations.
99
10-
The current code is configured as a 5-second rolling RTC alarm.
10+
The current code is configured as a 5-second rolling RTC alarm.
1111
*/
1212

13-
/*
14-
// This file is subject to the terms and conditions defined in
15-
// file 'LICENSE.md', which is part of this source code package.
13+
/*
14+
// This file is subject to the terms and conditions defined in
15+
// file 'LICENSE.md', which is part of this source code package.
1616
*/
1717

1818
#include "RTC.h"
@@ -31,10 +31,10 @@ void setup()
3131
// RTC.setToCompilerTime();
3232

3333
// Manually set RTC date and time
34-
RTC.setTime(0, 50, 59, 12, 3, 6, 20); // 12:59:50.000, June 3rd, 2020 (hund, ss, mm, hh, dd, mm, yy)
34+
rtc.setTime(0, 50, 59, 12, 3, 6, 20); // 12:59:50.000, June 3rd, 2020 (hund, ss, mm, hh, dd, mm, yy)
3535

3636
// Set the RTC's alarm
37-
RTC.setAlarm(0, 0, 0, 13, 3, 6); // 13:00:00.000, June 3rd (hund, ss, mm, hh, dd, mm). Note: No year alarm register
37+
rtc.setAlarm(0, 0, 0, 13, 3, 6); // 13:00:00.000, June 3rd (hund, ss, mm, hh, dd, mm). Note: No year alarm register
3838

3939
// Set the RTC alarm mode
4040
/*
@@ -47,8 +47,8 @@ void setup()
4747
6: Alarm match every minute (hundredths, seconds)
4848
7: Alarm match every second (hundredths)
4949
*/
50-
RTC.setAlarmMode(6); // Set the RTC alarm to match on minutes rollover
51-
RTC.attachInterrupt(); // Attach RTC alarm interrupt
50+
rtc.setAlarmMode(6); // Set the RTC alarm to match on minutes rollover
51+
rtc.attachInterrupt(); // Attach RTC alarm interrupt
5252

5353
// Print the RTC's alarm date and time
5454
Serial.print("Next alarm: "); printAlarm();
@@ -66,13 +66,13 @@ void loop()
6666
alarmFlag = false;
6767

6868
// Set the RTC's rolling alarm
69-
RTC.setAlarm(0,
70-
(RTC.seconds + alarmSeconds) % 60,
71-
(RTC.minute + alarmMinutes) % 60,
72-
(RTC.hour + alarmHours) % 24,
73-
RTC.dayOfMonth,
74-
RTC.month);
75-
RTC.setAlarmMode(6);
69+
rtc.setAlarm(0,
70+
(rtc.seconds + alarmSeconds) % 60,
71+
(rtc.minute + alarmMinutes) % 60,
72+
(rtc.hour + alarmHours) % 24,
73+
rtc.dayOfMonth,
74+
rtc.month);
75+
rtc.setAlarmMode(6);
7676

7777
// Print next RTC alarm date and time
7878
Serial.print("Next rolling alarm: "); printAlarm();
@@ -82,31 +82,29 @@ void loop()
8282
// Print the RTC's current date and time
8383
void printDateTime()
8484
{
85-
RTC.getTime();
86-
char dateTimeBuffer[25];
87-
sprintf(dateTimeBuffer, "20%02d-%02d-%02d %02d:%02d:%02d.%03d",
88-
RTC.year, RTC.month, RTC.dayOfMonth,
89-
RTC.hour, RTC.minute, RTC.seconds, RTC.hundredths);
90-
Serial.println(dateTimeBuffer);
85+
rtc.getTime();
86+
Serial.printf("20%02d-%02d-%02d %02d:%02d:%02d.%03d\n",
87+
rtc.year, rtc.month, rtc.dayOfMonth,
88+
rtc.hour, rtc.minute, rtc.seconds, rtc.hundredths);
89+
Serial.println();
9190
}
9291

9392
// Print the RTC's alarm
9493
void printAlarm()
9594
{
96-
RTC.getAlarm();
97-
char alarmBuffer[25];
98-
sprintf(alarmBuffer, "2020-%02d-%02d %02d:%02d:%02d.%03d",
99-
RTC.alarmMonth, RTC.alarmDayOfMonth,
100-
RTC.alarmHour, RTC.alarmMinute,
101-
RTC.alarmSeconds, RTC.alarmHundredths);
102-
Serial.println(alarmBuffer);
95+
rtc.getAlarm();
96+
Serial.printf("2020-%02d-%02d %02d:%02d:%02d.%03d\n",
97+
rtc.alarmMonth, rtc.alarmDayOfMonth,
98+
rtc.alarmHour, rtc.alarmMinute,
99+
rtc.alarmSeconds, rtc.alarmHundredths);
100+
Serial.println();
103101
}
104102

105103
// Interrupt handler for the RTC
106104
extern "C" void am_rtc_isr(void)
107105
{
108106
// Clear the RTC alarm interrupt.
109-
am_hal_rtc_int_clear(AM_HAL_RTC_INT_ALM);
107+
rtc.clearInterrupt();
110108

111109
// Set alarm flag
112110
alarmFlag = true;

0 commit comments

Comments
 (0)