Queue function execution

Hi, I am using the javascript library to call a function on my Spark Core and it works great.

One issue is that I want to be able to pause between events.

So if I get more than 1 click in a 10 second period it queues the clicks waits 10 seconds then calls the function.

Basically it is a Spark controlled Lucky Cat and I want to wait until the arm stops swinging before I swing it again.

Here is a video showing it in action.

Any thoughts?

Cheers.

Phil

You could create two counters. One counts the amount of functions it still has to execute, and decreases that by one after each execution. The second one could be a counter using millis() math to check whether or not 10s have passed after the last execution.

1 Like

I tried that and it din’t quite work as I expected.

I had the counting etc in side the function that is called.

I’ll try it again and post my code if it doesn’t work for me.

Thanks

Phil

You should try to keep as much of your functionalities outside your function calls. Try to only increment the “functions left to execute” by 1, and check for that in the loop. That should be more reliable.

1 Like