Open
Description
Target: Rasp Pico 1 sdk
Example project: https://wokwi.com/projects/430756341381772289
Code:
When I run it on the webpage I got the timers been canceled and created as expected, but when I run on the vs code extension, it won't create a new timer. To solve the problem I need to add a sleep between cancel and add a new timer.
cancel_repeating_timer(&timer_b);
+ sleep_ms(10);
add_repeating_timer_ms(300, timer_b_callback, NULL, &timer_b);
sleep_ms(1000);
Example code:
#include <stdio.h>
#include "pico/stdlib.h"
const int LED_PIN_R = 4;
volatile int cnt = 0;
bool timer_b_callback(repeating_timer_t* rt) {
printf("timer %d\n", cnt++);
return true; // keep repeating
}
int main() {
stdio_init_all();
gpio_init(LED_PIN_R);
gpio_set_dir(LED_PIN_R, GPIO_OUT);
repeating_timer_t timer_b;
add_repeating_timer_ms(100, timer_b_callback, NULL, &timer_b);
sleep_ms(1000);
while (true) {
printf("Canceled timer\n");
cancel_repeating_timer(&timer_b);
add_repeating_timer_ms(300, timer_b_callback, NULL, &timer_b);
sleep_ms(1000);
}
}
online it creates the new timer:
on vscode it get stuck