// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
#include "RPi_Pico_TimerInterrupt.h"
// store a byte received from UART
int incomingByte = 0;
int i = 0;
// Init RPI_PICO_Timer
RPI_PICO_Timer led_timer(1);
RPI_PICO_Timer uart_timer(2);
#define TIMER1_INTERVAL_MS 1000
#define TIMER2_INTERVAL_MS 2000
bool led_handler(struct repeating_timer *t){
(void) t;
static bool toggle = false;
Serial1.print("Builtin Led is ");
if (toggle){
Serial1.print("ON");
} else {
Serial1.print("OFF");
}
Serial1.print(" at led_timer: millis() = ");
Serial1.println(millis());
digitalWrite(LED_BUILTIN, toggle);
toggle = !toggle;
return true;
}
bool uart_handler(struct repeating_timer *t){
(void) t;
Serial1.print((String)"Hello "+i+++" from uart_handler at ");
Serial1.println(millis());
return true;
}
void setup(){
pinMode(LED_BUILTIN, OUTPUT);
Serial1.begin(115200);
Serial1.println("Press ENTER to start!");
delay(1000);
// Wait until a newline character is received
while (incomingByte != '\n') {
if (Serial1.available() > 0) {
incomingByte = Serial1.read();
}
}
Serial1.println("Starting IT Timer Example with Rpi pico!");
if (led_timer.attachInterruptInterval(TIMER1_INTERVAL_MS * 1000, led_handler)){
Serial1.print(F("Starting led_timer OK, millis() = ")); Serial1.println(millis());
} else
Serial1.println(F("Can't set led_timer. Select another freq. or timer"));
if (uart_timer.attachInterruptInterval(TIMER2_INTERVAL_MS * 1000, uart_handler))
{
Serial1.print(F("Starting uart_timer OK, millis() = ")); Serial.println(millis());
} else
Serial1.println(F("Can't set uart_timer. Select another freq. or timer"));
Serial1.println();
}
void loop()
{
// we can do whatever we want here!
while(1);
}