Pause a time after every x number frames rendered

Newbie to PB and to C++ in general. I’ve written a couple of patterns but stuck on figuring out how to pause a moving pattern after a fixed number of frames are rendered. I want to pause for a few seconds after every 16 frames are rendered.
I’ve read a couple of posts about “accumulating delta” but after trying for a long time just not getting there. I guess I’m having trouble wrapping my head around the “2-cycle engine” still. I appreciate help on this!

I may be not asking the right question, since I think very many redundant frames are sent before the pattern actually moves. To be very specific, I want to pause the Christmas Candy Cane pattern (in the “get patterns” PB patterns database) for a couple of seconds after the white blocks move to the position the red blocks once occupied. In other words, when a block moves one block distance.

I can bypass to the end of the render function for a couple of seconds, but sadly the string goes blank if nothing is rendered in the render function, rather than leaving alone what’s already been sent to the LED strip. This engine just likes to keep going and going without any way to pause it.

Well, it ain’t perfect, but it works, somewhat. The blocks slip more and less one block position. There has to be a better way.

blockLength = pixelCount / 9
startingPoint = 0
laststartingpoint=0

export function beforeRender(delta) {
  if (startingPoint > pixelCount) {
     startingPoint = 0  }
  startingPoint = startingPoint + delta/20 //speed

currenttime=time(.06) 
  if (currenttime <= .919) {  // Pause time
  startingPoint = laststartingpoint  }
}

export function render(index) {
  index = (index + startingPoint) % pixelCount
  if (index < blockLength) {
    // Red
    hsv(0,1,1)
  } else if (index >= blockLength && index < (2 * blockLength)) {
    // White
    hsv(30/360,0,1)
  } else if ((index > 2 * blockLength) && index < (3 * blockLength)) {
    // Green
    hsv(.33,1,.4)
  } else if ((index >= 3 * blockLength) && (index < (4 * blockLength))) {
    // Red
    hsv(0,1,1)
  } else if ((index > 4 * blockLength) && index < (5 * blockLength)) {
    // White
    hsv(30/360,0,1)
    hsv(240/360,1,1) // Blue
  } else if ((index >= 5 * blockLength) && (index < (6 * blockLength))) {
    // Green
    hsv(.33,1,.4)
  } else if ((index > 6 * blockLength) && index < (7 * blockLength)) {
    // Red
    hsv(0,1,1)
  } else if ((index >= 7 * blockLength) && (index < (8 * blockLength))) {
    // White
    hsv(30/360,0,1)
    hsv(.144,1,1) // Gold
  }
    else if ((index > 8 * blockLength) && (index < (9 * blockLength))) {
    // Green
   hsv(.33,1,.4) 
}
laststartingpoint=startingPoint
2 Likes

Pixelblaze currently renders continuously. At some point I think an API to skip animation frames would make sense. This comes up infrequently and it hasn’t become top of list.

Right now the best ways to do something like this is to buffer what the pixels will show (like in an array), only updating the pixels when you want the animation to change, or basing the animation on some variable that you control and intermittently update as you want the animation to progress. What you have above is an example of that.

These previous discussions might be helpful:

1 Like

Thank you! A series of arrays called up in a sequence and at various time intervals for rendering is a perfect idea for someone, like me, not wanting to go crazy trying to do something more elegant. I’m surprised this doesn’t come up more often, but I sure would benefit from a way to skip rendering that maintains the data last rendered to the pixels.

It’s likely because I am new to PB that all the time I spent due to a lack of a “pause” ability was a bit nerve-racking, but I’m getting to know the creature and liking it overall, a lot. I’ve programmed PIC microcontrollers (using PIC BasicPro --yeah, I’m that old) to do many LED strip patterns, having the control, of course, to send data out to the pixels if, when, and how many times I want to send it out. So much is new to me with the PB, but I’m getting there. I very much like the idea that I don’t have to cable to the PB to program and use it. That sold it for me. I also very much like that after a repower it remains in the state it was left in before power down, including the playlist. And, the web interface is a great thing! All this means, once I am done, anyone on the network can use it to select whatever patterns are in the list.

If it wasn’t for me asking web AI for programmable pixel controllers, I may never have found the PixelBlaze. The list is small.