API for changing patterns (… in a playlist)?

Is there any software API for changing patterns? I built a control box with next/previous buttons wired to the sensor board’s analog inputs (as well as a pot for brightness control) assuming there was but I can’t find any explanation of how to do it.

There are multiple forum topics making this request but they all end up using some other solution which requires different wiring which is not possible for my project.

EDIT: After thinking about this for a little while, I guess as a very last resort I could add all the patterns I wanted into one source file and create an array of render2D functions and index into that with a “currentPattern” pointer which I update according to the button presses. Ugly hack, but manageable if I keep it under source control and I need to modify each pattern to use the brightness knob anyhow…

1 Like

Would the pull-GPIO0-down-from-code trick mentioned (but not eventually used) in this post actually work? (I guess GPIO32 on a PixelBlaze v3)

(I’m kinda desperate for something—I have one unused line in the cable from the PB to the output expander/control box, but given GPIO0 needs to be pulled to ground to advance to the next pattern and the buttons are currently wired to pull up to 3.3V to make that work I’d have to entirely rewire the control box which I don’t want to have to do at this late stage… I fly out in 9 days!)

(@wizard, just a wild though on this general topic – would it be possible to set up a packet dispatcher in the Pixelblaze’s serial input reader so that we could send JSON websocket api commands as serial data?

That’d make it really easy to solve a lot of these physical control problems with super cheap IoT devices, without requiring wifi. It’s a low enough data rate that even the tiniest STM or arduino could handle physical controls, multiplex the sensor board data if present, and send the necessary JSON commands.)

3 Likes

I’d take a single API I could just send JSON with (skipping the “web” part of WebSockets entirely) at this point…

Good news @ratkins !
Here’s a beta build with sequencer APIs. This should let you implement what you are looking for with a bit of pattern code. You’ll need to copy some code to each pattern for reading/debouncing SB inputs and going next/prev, but cleaner than making a mega pattern.

Docs haven’t been updated, but here’s what’s new:

  • sequencerNext() Universal advance to next pattern, pretty much the same as button press. This API does nothing on a follower, so it won’t advance multiple times if you trigger it from a sensor board value; a follower will follow whatever pattern the leader is doing.
  • sequencerGetMode() returns the current mode, one of :
    SEQ_OFF: 0,
    SEQ_SHUFFLE_ALL: 1,
    SEQ_PLAYLIST: 2,
    SEQ_SYNCHRONIZED: 3 //follower

While in playlist mode, these APIs are available:

  • playlistGetPosition() current index of the playlist (starts at 0)
  • playlistSetPosition(position) switch to this item unless it’s already the playlist’s current position.
  • playlistGetLenght() number of items in the playlist

Going to the previous pattern is possible in playlist mode, and could work like this:

function previous() {
  var p = playlistGetPosition() - 1;
  p = mod(p, playlistGetLenght()) //wrap back to beginning, and ensure position fits length
  playlistSetPosition(p)
}
4 Likes

Wizard, you’re a champion! I’ll get onto this tonight and tell you how I go.

1 Like

You know, “playlistGetLenght()” is misspelled… is it just here in the forum, or is that typo baked into the firmware?

1 Like

It’s correct (and autocompletes) in the firmware.

1 Like