Initial Release
This commit is contained in:
45
rtc/hello_rtc/hello_rtc.c
Normal file
45
rtc/hello_rtc/hello_rtc.c
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "hardware/rtc.h"
|
||||
#include "pico/stdlib.h"
|
||||
#include "pico/util/datetime.h"
|
||||
|
||||
/// \tag::hello_rtc_main[]
|
||||
int main() {
|
||||
stdio_init_all();
|
||||
printf("Hello RTC!\n");
|
||||
|
||||
char datetime_buf[256];
|
||||
char *datetime_str = &datetime_buf[0];
|
||||
|
||||
// Start on Friday 5th of June 2020 15:45:00
|
||||
datetime_t t = {
|
||||
.year = 2020,
|
||||
.month = 06,
|
||||
.day = 05,
|
||||
.dotw = 5, // 0 is Sunday, so 5 is Friday
|
||||
.hour = 15,
|
||||
.min = 45,
|
||||
.sec = 00
|
||||
};
|
||||
|
||||
// Start the RTC
|
||||
rtc_init();
|
||||
rtc_set_datetime(&t);
|
||||
|
||||
// Print the time
|
||||
while (true) {
|
||||
rtc_get_datetime(&t);
|
||||
datetime_to_str(datetime_str, sizeof(datetime_buf), &t);
|
||||
printf("\r%s ", datetime_str);
|
||||
sleep_ms(100);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/// \end::hello_rtc_main[]
|
||||
Reference in New Issue
Block a user