/**
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdio.h>
#include "pico/stdlib.h"
volatile int g_timer_0 = 0;
bool timer_0_callback(repeating_timer_t *rt) {
g_timer_0 = 1;
return true; // keep repeating
}
int main() {
stdio_init_all();
int timer_0_hz = 5;
repeating_timer_t timer_0;
// negative timeout means exact delay (rather than delay between callbacks)
if (!add_repeating_timer_us(-1000000 / timer_0_hz, timer_0_callback, NULL, &timer_0)) {
printf("Failed to add timer\n");
return 1;
}
while(1){
if(g_timer_0){
printf("Hello timer 0 \n");
g_timer_0 = 0;
}
}
}
Loading
pi-pico-w
pi-pico-w