Hack star
Published © GPL3+

10 LED patterns using 16 LEDs-Raspberry Pi Pico Simulator

You can learn about 10 LED patterns and also play with the online Raspberry Pi Pico simulator. Learn - Play - Code - Share

BeginnerProtip1 hour1,680

Things used in this project

Hardware components

Raspberry Pi Pico
Raspberry Pi Pico
×1
LED
DIYables LED
×1
Jumper Wires
DIYables Jumper Wires
×1
Starter Kit
DIYables Starter Kit
Alternatively
×1

Software apps and online services

Wokwi Raspberry Pi Pico simulator

Story

Read more

Schematics

16LEDs and Pi Pico

Code

Pi Pico simulator for 16 LED chaser

Arduino
/**
   Controlling the Pi Pico GPIO with direct register access (SIO registers + IO Bank 0 registers)

   Code example from the Raspberry Pi Pico Deep Pico - The Deep Dive course:
   https://hackaday.io/course/178733-raspberry-pi-pico-and-rp2040-the-deep-dive
*/

/* Enables the SIO function for the given pin, by writing to the relevant CTRL register.
   (e.g. GPIO0_CTRL at 0x40014004) */
void enable_sio(int pin) {
  uint32_t *PIN_CTRL_REG = (uint32_t*)IO_BANK0_BASE + pin * 2 + 1;
  *PIN_CTRL_REG = 5; // 5 = SIO function
}

void setup() {
  // Enable the SIO function for pins GP0 to GP7
  for (int i = 0; i < 16; i++) {
    enable_sio(i);
  }

  // Enable output on pins GP0 to GP7:
  // sio_hw->gpio_oe points to 0xd0000020 (GPIO_OE)
  sio_hw->gpio_oe = 0b1111111111111111;

  // Set initial pin pattern
  // sio_hw->gpio_out points to 0xd0000010 (GPIO_OUT)
  sio_hw->gpio_out = 0b1010101010101010;
}

void loop() {
#if 0
  //pattern 1
  for (int i = 0; i < 20; i++) {
    sio_hw->gpio_togl = 0b1111111111111111;
    delay(420 - 20 * i);
  }



  //pattern 2
  for (int i = 0; i < 16; i++)
  {
    sio_hw->gpio_out = 65535 >> i;
    delay(300);
  }


  //pattern 3
  for (int i = 0; i < 16; i++)
  {
    sio_hw->gpio_out = (65535 >> i);
    sio_hw->gpio_togl = 0b1111111111111111;
    delay(300);
  }


  //pattern 4
  for (int i = 0; i < 16; i++)
  {
    sio_hw->gpio_out = 1 << i;
    delay(100);
  }
#endif

  //pattern 5
  for (int i = 0; i < 16; i++)
  {
    sio_hw->gpio_out = 32767 >> i;
    delay(100);
  }

  //pattern 6
  sio_hw->gpio_out = 65535;
  for (int i = 0; i < 16; i++)
  {
    sio_hw->gpio_togl = 0b1111111111111111;
    delay(200);
  }

  //pattern 7
  sio_hw->gpio_out = 65280;
  for (int i = 0; i < 8; i++)
  {
    sio_hw->gpio_togl = 0b1111111111111111;
    delay(300);
  }

  //pattern 8
  sio_hw->gpio_out = 61680;
  for (int i = 0; i < 16; i++)
  {
    sio_hw->gpio_togl = 0b1111111111111111;
    delay(300);
  }

  //pattern 9
  sio_hw->gpio_out = 52428;
  for (int i = 0; i < 16; i++)
  {
    sio_hw->gpio_togl = 0b1111111111111111;
    delay(300);
  }

  //pattern 10
  sio_hw->gpio_out = 43690;
  for (int i = 0; i < 16; i++)
  {
    sio_hw->gpio_togl = 0b1111111111111111;
    delay(300);
  }

}

Credits

Hack star

Hack star

75 projects • 97 followers
an Arduino enthusiast and an electronic hobbyist

Comments