Code examples and extended information
In the Waspmote Development section you can find complete examples: https://development.libelium.com/waspmote/code-examples
Next lines show a complete example of use of the RTC functions.
1
/*
2
* ------Waspmote RTC Complete Example--------
3
*
4
* Explanation: This example shows how to read the temperature using
5
* the sensor integrated in Waspmote
6
*
7
* Copyright (C) 2012 Libelium Comunicaciones Distribuidas S.L.
8
* http://www.libelium.com
9
*
10
* This program is free software: you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation, either version 3 of the License, or
13
* (at your option) any later version.
14
*
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
19
*
20
* You should have received a copy of the GNU General Public License
21
* along with this program. If not, see \http://www.gnu.org/licenses/\.
22
*
23
* Version: 0.1
24
* Design: David Gascón
25
* Implementation: Marcos Yarza
26
*/
27
28
void setup()
29
{
30
// Setup for Serial port over USB
31
USB.ON();
32
USB.println(F("USB port started..."));
33
// Powers RTC up, init I2C bus and read initial values
34
USB.println(F("Init RTC"));
35
RTC.ON();
36
}
37
38
void loop()
39
{
40
USB.println(F(\"+++++++++++++++++++++++++++++++++++++++++++++++++++\"));
41
42
// Setting time
43
RTC.setTime("09:10:20:03:17:35:00");
44
USB.print(F("Time: "));
45
USB.println(RTC.getTime());
46
47
// Setting and getting Alarms
48
RTC.setAlarm1("20:17:35:30", RTC_ABSOLUTE, RTC_ALM1_MODE2);
49
USB.print(F("Alarm1: "));
50
USB.println(RTC.getAlarm1());
51
52
// Setting Waspmote to Low-Power Consumption Mode
53
PWR.sleep(ALL_OFF);
54
55
// After setting Waspmote to power-down, UART is closed, so it
56
// is necessary to open it again
57
USB.ON();
58
59
// Waspmote wakes up at '17:35:30'
60
if( intFlag & RTC_INT )
61
{
62
intFlag &= ~(RTC_INT); // Clear flag
63
Utils.blinkLEDs(1000); // Blinking LEDs
64
Utils.blinkLEDs(1000); // Blinking LEDs
65
}
66
delay(5000);
67
}
Copied!
Copy link