Simple sequencing - best practice

Folks,
Happy new year.. . I'm working on a 10m long keyboard project..

I need some general suggestions on a way to run a simple sequence of commands in order .. eg

command 1: flash all keys in random order for 10 seconds,
command 2: select two sets of 8 keys, assign a sound to them and allow them to be played for 10 seconds,
command 3, 'rotate/ the key assignment so the two sets of selected 8 keys more the the right a random number of spaces, then allow the keys to be played for 10 seconds ,.then repeat this process 5 times..
etc....
command 4: switch to a simple game of keyboard pong for 3 min
go bag to command 1 and repeat until you get a 'stop/ command.

what's key here is:

  • it must be easy to modify the order and parameters of the sequence with no changes to the node red floors.. eg.. the input would come as a JSON , array or other structure. That structure would call out predefined actions and their parameters
  • the first command must complete before the next one launches..
  • ideally I would be able to include in this list the construct "do this action for x seconds: .. or " do this action y times"
  • ideally I could either supply fixed arguments to the actions or provide them with random values within ranges.

Again, I'm not asking anyone to engineer this completely for me but I'm looking for a good idea on general structure.. eg... should I do this as a hierarchical JSON ? .. an array of Arrays ? .. Either way.. what would the general control flow be so that each command is executed after the previous one completes.. ?

Any general suggestions much appreciated !

-jc

Hi John, that is quite the task (and interesting too).

The would approach I would take is make each of the 4 features work as expected using standard flows & nodes then figure out how to sequence them then how to make parts of them dynamic (be that JSON or Arrays settings / loaded from file / transmitted via MQTT etc).

I suspect you are fairly up to speed with node red already so I would say get stuck in and you should spot common parts or areas than can be simplified and parameterised as you go.

One last point, though I wouldn't suggest a state machine node (they hide too much of the flow env for my liking) I would probably advise you take a state-machine-like approach to the sequencing - perhaps a context variable named "mode" that tracks the current state of operation. then use switch nodes to direct flow of messages based on the current mode.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.