#include <stdio.h>
#include "pico/stdlib.h"
#include "pico/time.h"
#define LED_PIN 26
#define BUTTON_PIN 14 // GPIO 14 for the button
int main() {
stdio_init_all();
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
gpio_init(BUTTON_PIN);
gpio_set_dir(BUTTON_PIN, GPIO_IN);
gpio_pull_up(BUTTON_PIN);
uint32_t start_time = to_ms_since_boot(get_absolute_time());
uint32_t current_time = start_time;
uint32_t elapsed_time = 0;
uint32_t blink_count = 0;
uint32_t interval = 1000; // 1 second interval
uint32_t blink_target[] = {30, 20, 10}; // Blink targets for each minute
bool reverse = false; // Flag to reverse blinking pattern
while (1) {
current_time = to_ms_since_boot(get_absolute_time());
elapsed_time = current_time - start_time;
uint32_t minute = elapsed_time / (60 * 1000); // Time in minutes
if (minute >= 3) // Stop after 3 minutes
break;
// Check if button is pressed to reverse blinking pattern
if (gpio_get(BUTTON_PIN) == 0) {
reverse = !reverse;
while (gpio_get(BUTTON_PIN) == 0); // Wait until button is released
// Reset start time and blink count for next minute
start_time = to_ms_since_boot(get_absolute_time());
blink_count = 0;
}
uint32_t target_index = reverse ? (2 - minute) : minute; // Index for blink_target
if (blink_count < blink_target[target_index]) {
gpio_put(LED_PIN, 1); // LED ON
sleep_ms(100); // LED ON time
gpio_put(LED_PIN, 0); // LED OFF
sleep_ms(100); // LED OFF time
blink_count++;
} else {
// Reset start time and blink count for next minute
start_time = to_ms_since_boot(get_absolute_time());
blink_count = 0;
}
}
return 0;
}