/**
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "pico/stdlib.h"
#include "pico/time.h"
int main()
{
#ifndef PICO_DEFAULT_LED_PIN
#warning blink example requires a board with a regular LED
#else
const uint LED_PIN = PICO_DEFAULT_LED_PIN;
const uint BUTTON_PIN = 14; // Change to the appropriate GPIO pin for the button
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
gpio_init(BUTTON_PIN);
gpio_set_dir(BUTTON_PIN, GPIO_IN);
int blink_count = 1;
int minute = 1;
bool reverse_pattern = false; // Flag to toggle the pattern
while (true)
{
// Check if the button is pressed to toggle the pattern
if (gpio_get(BUTTON_PIN) == 0)
{
reverse_pattern = !reverse_pattern;
sleep_ms(200); // Debounce delay
}
// Blink LED according to the current minute and the pattern direction
if (!reverse_pattern)
{
switch (minute) {
case 1:
while (blink_count <= 10)
{
gpio_put(LED_PIN, 1);
sleep_ms(500);
gpio_put(LED_PIN, 0);
sleep_ms(500);
blink_count++;
}
minute++;
break;
case 2:
while (blink_count <= 20)
{
gpio_put(LED_PIN, 1);
sleep_ms(500);
gpio_put(LED_PIN, 0);
sleep_ms(500);
blink_count++;
}
minute++;
break;
case 3:
while (blink_count <= 30)
{
gpio_put(LED_PIN, 1);
sleep_ms(500);
gpio_put(LED_PIN, 0);
sleep_ms(500);
blink_count++;
}
break;
}
}
else
{
// Reverse pattern
switch (minute)
{
case 1:
while (blink_count <= 30)
{
gpio_put(LED_PIN, 1);
sleep_ms(500);
gpio_put(LED_PIN, 0);
sleep_ms(500);
blink_count++;
}
minute++;
break;
case 2:
while (blink_count <= 20)
{
gpio_put(LED_PIN, 1);
sleep_ms(500);
gpio_put(LED_PIN, 0);
sleep_ms(500);
blink_count++;
}
minute++;
break;
case 3:
while (blink_count <= 10)
{
gpio_put(LED_PIN, 1);
sleep_ms(500);
gpio_put(LED_PIN, 0);
sleep_ms(500);
blink_count++;
}
break;
}
}
blink_count = 1;
// Wait for 60 seconds
sleep_ms(60000);
}
#endif
}