/**
* Copyright (c) 2022 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "pico/stdlib.h"
#include "stdio.h"
#define LED_PIN 11
#define BTN_PIN 26
volatile uint8_t counter = 0;
uint32_t ciclo;
void led_hertz(int hertz)
{
int start_time = to_ms_since_boot(get_absolute_time());
hertz = hertz * 2;
while (to_ms_since_boot(get_absolute_time()) - start_time < 1000)
{
ciclo = 1000 / hertz;
gpio_put(LED_PIN, 1);
sleep_ms(ciclo);
gpio_put(LED_PIN, 0);
sleep_ms(ciclo);
}
}
void blink_counter() {
if (!gpio_get(BTN_PIN)) {
counter++;
printf("Botão pressionado");
sleep_ms(10);
}
while (!gpio_get(BTN_PIN)) {
sleep_ms(100);
}
if (counter == 5){
for (int i = 0; i <= 10; i++)
{
led_hertz(10);
printf("Blinked for %d\n second(s)", i);
}
counter = 0;
}
}
int main() {
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
gpio_init(BTN_PIN);
gpio_set_dir(BTN_PIN, GPIO_IN);
gpio_pull_up(BTN_PIN);
while (true)
{
blink_counter();
sleep_ms(1);
}
}