#include <stdio.h>
#include "pico/stdlib.h"
#include "pico/cyw43_arch.h"
#include <time.h>
#define LED_ROJO 0
#define LED_VERDE 4
bool x;
bool level=false;
bool repeating_timer_callback (struct repeating_timer *t)
{
level=level?false:true;
gpio_put(LED_ROJO, level);
}
bool repeating_timer_callback_1 (struct repeating_timer *t);
int main() {
int c = 1;
const uint8_t PULSADOR = 28;
gpio_init(PULSADOR);
gpio_set_dir(PULSADOR, GPIO_IN);
gpio_init(LED_ROJO);
gpio_set_dir(LED_ROJO, GPIO_OUT);
gpio_init(LED_VERDE);
gpio_set_dir(LED_VERDE, GPIO_OUT);
//stdio_init_all();
struct repeating_timer timer;
add_repeating_timer_ms(500,repeating_timer_callback,NULL,&timer);
//struct repeating_timer timer_1;
//add_repeating_timer_ms(10, repeating_timer_callback_1, NULL, &timer_1);
while (true) {
if (gpio_get(PULSADOR)){
//c = c + 1;
//if (c % 2 == 0){
x = true;
//gpio_put(LED_VERDE, x);
//}
//else {
//x = false;
} else{
x = false;
}
//gpio_put(LED_VERDE);
gpio_put(LED_VERDE, x);
sleep_ms(50);
}
}
/*
#include <stdio.h>
#include "pico/stdlib.h"
#include "pico/cyw43_arch.h"
#define LED_RED 0
#define LED_GREEN 4
#define PUSH 28
bool level = false;
bool repeating_timer_callback (struct repeating_timer *t) {
level = !level; //? false:true;
gpio_put(LED_RED, level);
}
/*
void button_callback(uint gpio, uint32_t events) {
int cnt = 0;
if (cnt == 0) {
gpio_put(LED_GREEN, true);
cnt++;
}
if (cnt == 1) {
gpio_put(LED_GREEN, false);
cnt--;
}
}
/*
int main() {
gpio_init(LED_RED);
gpio_set_dir(LED_RED, GPIO_OUT);
gpio_init(LED_GREEN);
gpio_set_dir(LED_GREEN, GPIO_OUT);
gpio_init(PUSH);
gpio_set_dir(PUSH, GPIO_OUT);
gpio_pull_up(PUSH);
//gpio_set_irq_enabled_with_callback(PUSH, 0x04, 1, button_callback);
struct repeating_timer timer;
add_repeating_timer_ms(500, repeating_timer_callback, NULL, &timer);
//stdio_init_all(); must stay off for some reason
while (true) {
if (gpio_get(PUSH)) {
gpio_put(LED_GREEN, true);
}
sleep_ms(250); // debounce, testing different times
if (gpio_get(PUSH)) {
gpio_put(LED_GREEN, false);
}
sleep_ms(250);
}
}
*/