#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/timer.h"
#include "hardware/gpio.h"

#define LED_PIN 20
bool LED_STATE = 0;

// Define a structure to hold the data to pass to the callback
typedef struct {
  const char* message;
  int data;
} alarm_data_t;

// The callback function that will be called when the alarm triggers
bool alarm_callback(alarm_id_t id, void *user_data) {
  //LED_STATE = !LED_STATE;
  //gpio_put(LED_PIN, LED_STATE);
  alarm_data_t* data = (alarm_data_t*)user_data;
  printf("Alarm triggered! Message: %s, Data: %d\n", data->message, data->data);
  LED_STATE = !LED_STATE;
  gpio_put(LED_PIN, LED_STATE);
  // Returning true will remove the alarm
  return true;
}

int main() {
  stdio_init_all();
  gpio_init(LED_PIN);
  gpio_set_dir(LED_PIN, GPIO_OUT);
  LED_STATE = 0;
  // Prepare the data to pass to the callback
  alarm_data_t my_alarm_data = {
    .message = "Hello from the alarm",
    .data = 42
  };

  // Set an alarm to trigger after 2000 milliseconds (2 seconds)
  add_alarm_in_ms( 2000, alarm_callback, &my_alarm_data, false);
  
  while (1) {
    // Main loop doing other tasks
    tight_loop_contents();
  }

  return 0;
}
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT