#include <stdio.h>
#include "pico/stdlib.h"
#define DEBOUNCE 200 // define debounce is 200
int main() {
unsigned int gpio , ogpio , fmgpio ; // initialise the variables
unsigned int led_pins = 0xfc; // initialise all led's
unsigned int sw_pin = 15; // initialise switch y as pin 15 on its own
for (gpio = 12; gpio < 15; gpio ++) { // set up other switches
gpio_init(gpio);
gpio_set_dir(gpio , GPIO_IN);
gpio_pull_up(gpio);
}
gpio_init(sw_pin); // set up switch y
gpio_set_dir(sw_pin, GPIO_IN);
gpio_pull_up(sw_pin);
for (gpio = 2; gpio < 8; gpio ++) { // set up led's
gpio_init(gpio);
gpio_set_dir(gpio , GPIO_OUT);
}
while (1) {
for (gpio = 12; gpio <15; gpio ++)
{
ogpio = gpio - 10; // ogpio value or formula
fmgpio = ogpio + 3; // fmgpio value or formula
gpio_put(ogpio , !gpio_get(gpio)); // turn on the led's that are a consequence of the formula for ogpio
gpio_put(fmgpio , !gpio_get(gpio)); // turn on the led's that are a consequence of the formula for fmgpio
if (!gpio_get(sw_pin)) // if statement , if switch y is pressed then:
{
gpio_put_masked(led_pins, 0xfc); // turn on all LED's
}
else{ // else statment
sleep_ms(DEBOUNCE);// turn off all LED's when switch y is released
}
}
}
}