#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/gpio.h"
#define BUTTON_PIN 14
#define LED_PIN 0
void blinkLED(int times) {
for (int i = 0; i < times; i++) {
gpio_put(LED_PIN, 1); // Turn the LED on
sleep_ms(300); // Wait for 300 milliseconds
gpio_put(LED_PIN, 0); // Turn the LED off
sleep_ms(300); // Wait for 300 milliseconds
}
}
int main() {
stdio_init_all();
gpio_init(BUTTON_PIN);
gpio_set_dir(BUTTON_PIN, GPIO_IN);
gpio_pull_down(BUTTON_PIN); // Pull down button pin
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT); // Set LED pin as output
bool reverse = false; // Toggle variable
while (true) {
if (gpio_get(BUTTON_PIN)) { // Check if button is pressed
printf("Button pressed. Toggling LED blinking pattern...\n");
reverse = !reverse; // Toggle the mode
if (!reverse) {
// If not in reverse mode, blink LED according to the statement
blinkLED(10); // Blink 10 times in the first minute
sleep_ms(500);
blinkLED(20); // Blink 20 times in the second minute
sleep_ms(500);
blinkLED(30); // Blink 30 times in the third minute
sleep_ms(500);
} else {
// If in reverse mode, reverse the blinking pattern
blinkLED(30); // Blink 30 times in the first minute
sleep_ms(500);
blinkLED(20); // Blink 20 times in the second minute
sleep_ms(500);
blinkLED(10); // Blink 10 times in the third minute
sleep_ms(500);
}
} else {
printf("Button not pressed. Blinking LED normally...\n");
// If the button is not pressed, follow normal blinking pattern
blinkLED(10); // Blink 10 times in the first minute
sleep_ms(500);
blinkLED(20); // Blink 20 times in the second minute
sleep_ms(500);
blinkLED(30); // Blink 30 times in the third minute
sleep_ms(500);
}
sleep_ms(250);
}
}