#include <stdio.h>
#include <pico/stdlib.h>
#include <hardware/gpio.h>
#include <unistd.h>
#define LED_PIN 6
#define BUTTON_PIN 20
void blinkLED(int count, int delay_ms) {
for (int i = 0; i < count; i++) {
gpio_put(LED_PIN, 1); // Turn on LED
sleep_ms(delay_ms);
gpio_put(LED_PIN, 0); // Turn off LED
sleep_ms(delay_ms);
}
}
int main() {
stdio_init_all();
// Initialize GPIO pins for LED and toggle button
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);
int minute = 0;
bool reversePattern = false;
while (minute < 3) {
int blinkCount;
if (reversePattern) {
blinkCount = (3 - minute) * 10; // Reverse blink count for the current minute
} else {
blinkCount = (minute + 1) * 10; // Original blink count for the current minute
}
printf("Blinking LED %d times in minute %d\n", blinkCount, minute + 1);
blinkLED(blinkCount, 500); // Blink LED with a delay of 500ms between blinks
sleep_ms(60000 - blinkCount * 1000); // Sleep for remaining seconds in the minute
// Check if the toggle button is pressed to reverse the pattern
if (!gpio_get(BUTTON_PIN)) {
reversePattern = !reversePattern;
printf("Blinking pattern reversed!\n");
}
minute++;
}
return 0;
}