#include <stdio.h>
#include "pico/stdlib.h"
const int PUSH_BUTTON = 16;
const int RED_LED = 15;
int previous_button_position =0;
int Push_button=0;
int LED_STATE = 1;
void status()
{
Push_button = gpio_get(PUSH_BUTTON);
if (Push_button != previous_button_position )
{
previous_button_position = Push_button;
if (Push_button == 0)
{
LED_STATE = LED_STATE ^ 1;//XOR operation
}
}
}
int main() {
gpio_init(RED_LED);
gpio_init(PUSH_BUTTON);
gpio_set_dir(PUSH_BUTTON, GPIO_IN);
gpio_set_dir(RED_LED, GPIO_OUT);
while (true)
{
if(LED_STATE==1)
{
gpio_put(RED_LED, 1);
sleep_ms(250);
status();
gpio_put(RED_LED, 0);
sleep_ms(250);
status();
}
gpio_put(RED_LED, 0);
status();
}
}