2022-04-19T19:58:40
This commit is contained in:
40
06_timer/src/timer.c
Normal file
40
06_timer/src/timer.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <stdio.h>
|
||||
#include "pico/stdlib.h"
|
||||
#include "pico/time.h"
|
||||
#include "hardware/timer.h"
|
||||
#include "pico/binary_info.h"
|
||||
|
||||
// 알람 고유 번호와 사용자 데이터를 매개 변수로 전달 받습니다.
|
||||
int64_t alarm_callback(alarm_id_t id, void *user_data)
|
||||
{
|
||||
printf("Timer %d fired!\n", (int)id);
|
||||
|
||||
// 반환값으로 마이크로 초 단위의 값을 사용해서 경과 시간 후 다시 실행되도록 지정할 수 있습니다.
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool repeating_timer_callback(struct repeating_timer *t)
|
||||
{
|
||||
printf("Repeat at %lld\n", time_us_64());
|
||||
// false를 반환하면 반복이 중단됩니다.
|
||||
return true;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
bi_decl(bi_program_description("Timer"));
|
||||
|
||||
stdio_init_all();
|
||||
alarm_pool_init_default();
|
||||
|
||||
alarm_id_t alarmId = add_alarm_in_ms(10000, alarm_callback, NULL, false);
|
||||
|
||||
struct repeating_timer timer;
|
||||
add_repeating_timer_ms(1500, repeating_timer_callback, NULL, &timer);
|
||||
|
||||
while (true)
|
||||
{
|
||||
printf("Currently, %u", time_us_32());
|
||||
sleep_ms(1000);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user