Skip to content

Instantly share code, notes, and snippets.

@doctea
Created February 7, 2024 00:01
Show Gist options
  • Save doctea/a7b4b401a9169ca555b020b3dcc15d95 to your computer and use it in GitHub Desktop.
Save doctea/a7b4b401a9169ca555b020b3dcc15d95 to your computer and use it in GitHub Desktop.
#include <Arduino.h>
#include "pico/sync.h"
struct repeating_timer timer;
const int us_interval = 1000 * 1000 * 1;
volatile bool ready_for_phase_2 = false;
volatile bool phase_2_started = false;
bool handlerISR(repeating_timer *timer)
{
static int counter = 0;
Serial.println("handlerISR called!");
counter++;
if (counter<10)
return true;
ready_for_phase_2 = true;
if (phase_2_started) return true;
return false;
}
void setup() {
// put your setup code here, to run once:
/*for (int i = 0 ; i < 5 ; i++) {
Serial.println("starting up...");
delay(1000);
}*/
add_repeating_timer_us(-us_interval, &handlerISR, NULL, &timer);
}
void loop() {
// put your main code here, to run repeatedly:
if (ready_for_phase_2 && !phase_2_started) {
phase_2_started = true;
Serial.println("setting up new negative timer...!");
cancel_repeating_timer(&timer);
add_repeating_timer_us(-us_interval, &handlerISR, NULL, &timer);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment