PixelBlaze and Pico2W

I am looking to do a project that involves buttons and PixelBlaze LED matrices. I want to be able to click a button and have the pattern change. What would be the best way to do this? Would this need a Pico2W and integrate it to the PixelBlaze or something different?

Hey - the pico already has a button and a single press will cycle through the patterns loaded on the board (or in the current playlist).

The pico can drive matrices fine. What did you mean by “Pico2W”? I think there’s only been two Pico models, the one with the accelerometer/gyro/solder pads, and previously, the one without.

Pico2W is the specific pico that I have. Is there a way to have multiple buttons and one click will play a certain pattern on Pixelblaze matrices?

Oh ok, so Pico2W is the device name you assigned it in Settings, I see.

It’d be some work but it’s definitely possible.

If you have the newer Pico version with all the pads on the bottom, you can set up a 3.3V voltage divider where each button would make a different voltage divider between the GND and “3V” pad - then sense the value on one of the analog input capable pads (pin/pad 33, 34, 36, or 39).

                          1KΩ 
                    |----/\/\/\---BTN1---|
        10KΩ        |     10KΩ           |
GND ---/\/\/\--T----|----/\/\/\---BTN2---|--- 3V
               |    |     100KΩ          |
             PAD33  |----/\/\/\---BTN2---|

Then you’d need to copy-paste a snippet of code into the beforeRender() of each pattern you want to activate with buttons. That code would read the value of pin 33 and then convert the values you measure (from finding then in the variable watcher) to a position in the current playlist for the pattern you want to activate. They’re normalized to 0-1, so if pin 33 were to read 3.3V, the value would be very close to 1.0.

For the resistor values above, pushing just BTN1 would result in a value close to 0.1

BTN1 alone forms a divider of 10 kΩ (bottom leg) and 1 kΩ (top leg). That puts the sensed branch at roughly 10% of 3.3 V, so you get about 0.33 V. Pixelblaze normalizes ADC reads to 0–1, so BTN1 gives you a value around 0.10, BTN2 maybe around 0.50, and BTN3 around 0.90.

Here’s some example code that might work (untested):

pinMode(33, INPUT_PULLDOWN)

export function beforeRender(delta) {
  // Read analog voltage on pin 33, normalized 0–1
  var btn = analogRead(33)

  if (btn > 0.05) { // Something is pressed
    // Example: pick one of N patterns based on voltage
    var N = 3 // number of patterns in your playlist
    var idx = floor(btn * N)

    // You could then use idx to pick which pattern to jump to - I forget if the playlist is 0-indexed but I assume so
    playlistSetPosition(idx)
  }
}

Your wiring will give each button (or combination) its own voltage “island” to threshold on. Once those values appear in the variable watcher, you can carve up the 0–1 space however you like.