#include <Arduino.h>

// Define GPIO pins
#define LED_PIN 25
#define TOGGLE_BUTTON_PIN 16

// Variables to track states
int minute = 1;               // Tracks the current minute interval
int blinks_per_minute = 10;   // Default blinks per minute
bool reverse = false;         // Flag to reverse blink rate sequence

// Function to initialize GPIO
void gpio_setup() {
    // Initialize LED pin as output
    pinMode(LED_PIN, OUTPUT);

    // Initialize button pin as input with pull-down
    pinMode(TOGGLE_BUTTON_PIN, INPUT_PULLDOWN);
}

// Setup function (called once)
void setup() {
    gpio_setup(); // Initialize GPIO pins
}

// Main loop (runs continuously)
void loop() {
    // Check if the button is pressed
    if (digitalRead(TOGGLE_BUTTON_PIN) == HIGH) {
        reverse = !reverse; // Toggle the reverse flag
        delay(200);         // Debounce delay
    }

    // Update the blink rate based on the current state
    if (reverse) {
        switch (minute) {
            case 1: blinks_per_minute = 30; break;
            case 2: blinks_per_minute = 20; break;
            case 3: blinks_per_minute = 10; break;
            default: blinks_per_minute = 10; break;
        }
    } else {
        switch (minute) {
            case 1: blinks_per_minute = 10; break;
            case 2: blinks_per_minute = 20; break;
            case 3: blinks_per_minute = 30; break;
            default: blinks_per_minute = 10; break;
        }
    }

    // Blink the LED for the specified number of times
    int blink_cycle_time = 1000;                 // Each blink cycle takes 1 second
    int total_blink_time = blinks_per_minute * blink_cycle_time; // Total blinking duration in ms

    for (int i = 0; i < blinks_per_minute; i++) {
        digitalWrite(LED_PIN, HIGH); // Turn LED on
        delay(500);                  // Wait 500ms
        digitalWrite(LED_PIN, LOW);  // Turn LED off
        delay(500);                  // Wait 500ms
    }

    // Sleep for the remaining time in the minute
    if (total_blink_time < 60000) {
        delay(60000 - total_blink_time);
    }

    // Cycle through minutes
    minute++;
    if (minute > 3) {
        minute = 1;  // Reset to the first minute
    }
}
$abcdeabcde151015202530fghijfghij
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT