#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/gpio.h"
#define LED_PIN 16
#define BUTTON_TOGGLE 15
volatile bool reverse_pattern = false;
void button_isr(){
reverse_pattern = !reverse_pattern;
}
// Function to blink LED
void blinkLED(int blink_count) {
for (int i = 0; i < blink_count; i++) {
gpio_put(LED_PIN, 1);
sleep_ms(250);
gpio_put(LED_PIN, 0);
sleep_ms(250);
printf("%d\n", i+1);
}
}
// Function to introduce delay in seconds
void delay(int seconds) {
for (int i = 0; i < seconds; i++) {
sleep_ms(1000);
}
}
int main() {
stdio_init_all();
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
gpio_init(BUTTON_TOGGLE);
gpio_set_dir(BUTTON_TOGGLE, GPIO_IN);
gpio_pull_up(BUTTON_TOGGLE);
gpio_set_irq_enabled_with_callback(BUTTON_TOGGLE, GPIO_IRQ_EDGE_FALL, true, &button_isr); // Enable interrupt on button press
int blink_count[3] = {10, 20, 30}; // Initial blink counts
while (true) {
// Blink LEDs according to current blink pattern
if(!reverse_pattern){
for (int i = 0; i < 3; i++) {
blinkLED(blink_count[i]);
delay(60); // Delay for one minute
}
}
else{
printf("Button Pressed");
for (int i = 2; i >=0 ; i--) {
blinkLED(blink_count[i]);
delay(60); // Delay for one minute
}
}
}
return 0;
}