Untitled

 avatar
unknown
c_cpp
2 months ago
2.1 kB
4
Indexable
// Include the Pico SDK
#include "pico/stdlib.h"

// Define LED pins as bit masks
#define LED_GP21 (1 << 21)
#define LED_GP20 (1 << 20)
#define LED_GP28 (1 << 28)
#define LED_GP3  (1 << 3)
#define LED_GP2  (1 << 2)
#define LED_GP5  (1 << 5)
#define LED_GP4  (1 << 4)
#define LED_GP14 (1 << 14)

// Combine all LEDs into one mask
#define LED_MASK (LED_GP21 | LED_GP20 | LED_GP28 | LED_GP3 | LED_GP2 | LED_GP5 | LED_GP4 | LED_GP14)

// Simple delay (~0.3s, may need tuning)
void wait()
{
   for ( unsigned long i = 0; i < 10000000; i++)
   {
      __asm("nop");
   }0
}

void setup()
{
    // Set all pins to SIO (GPIO function)
    io_bank0_hw->io[21].ctrl = IO_BANK0_GPIO0_CTRL_FUNCSEL_VALUE_SIO_0;
    io_bank0_hw->io[20].ctrl = IO_BANK0_GPIO0_CTRL_FUNCSEL_VALUE_SIO_0;
    io_bank0_hw->io[28].ctrl = IO_BANK0_GPIO0_CTRL_FUNCSEL_VALUE_SIO_0;
    io_bank0_hw->io[3].ctrl  = IO_BANK0_GPIO0_CTRL_FUNCSEL_VALUE_SIO_0;
    io_bank0_hw->io[2].ctrl  = IO_BANK0_GPIO0_CTRL_FUNCSEL_VALUE_SIO_0;
    io_bank0_hw->io[5].ctrl  = IO_BANK0_GPIO0_CTRL_FUNCSEL_VALUE_SIO_0;
    io_bank0_hw->io[4].ctrl  = IO_BANK0_GPIO0_CTRL_FUNCSEL_VALUE_SIO_0;
    io_bank0_hw->io[14].ctrl = IO_BANK0_GPIO0_CTRL_FUNCSEL_VALUE_SIO_0;

    // Set all as output
    sio_hw->gpio_oe_set = LED_MASK;
}

void loop()
{
    // GP21
    sio_hw->gpio_set = LED_GP21;
    wait();
    sio_hw->gpio_clr = LED_GP21;

    // GP20
    sio_hw->gpio_set = LED_GP20;
    wait();
    sio_hw->gpio_clr = LED_GP20;

    // GP28
    sio_hw->gpio_set = LED_GP28;
    wait();
    sio_hw->gpio_clr = LED_GP28;

    // GP3
    sio_hw->gpio_set = LED_GP3;
    wait();
    sio_hw->gpio_clr = LED_GP3;

    // GP2
    sio_hw->gpio_set = LED_GP2;
    wait();
    sio_hw->gpio_clr = LED_GP2;

    // GP5
    sio_hw->gpio_set = LED_GP5;
    wait();
    sio_hw->gpio_clr = LED_GP5;

    // GP4
    sio_hw->gpio_set = LED_GP4;
    wait();
    sio_hw->gpio_clr = LED_GP4;

    // GP14
    sio_hw->gpio_set = LED_GP14;
    wait();
    sio_hw->gpio_clr = LED_GP14;
}
Editor is loading...
Leave a Comment