Skip to content

Instantly share code, notes, and snippets.

@dceejay
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dceejay/5c4c0f5a08d4e91ea14d to your computer and use it in GitHub Desktop.
Save dceejay/5c4c0f5a08d4e91ea14d to your computer and use it in GitHub Desktop.
Simple way to pulse output n times

From v.0.10.5 fixes the function node supports sending messages from within. This means that you can iterate over a loop internally if required...

The flow attached shows how this can be used to pulse an output n times in response to an input.

[{"id":"d6d71397.2928f","type":"inject","name":"","topic":"","payload":"5","payloadType":"string","repeat":"","crontab":"","once":false,"x":392,"y":139,"z":"6480e14.f9b7f2","wires":[["741833ea.8be7cc"]]},{"id":"741833ea.8be7cc","type":"function","name":"BLINK n","func":"\nvar o = false;\nfor (var i=0; i<(msg.payload*2); i++) {\n node.send( {payload:+(o=!o)} )\n}\n\nreturn null;","outputs":1,"valid":true,"x":549,"y":171,"z":"6480e14.f9b7f2","wires":[["c79ca805.386358"]]},{"id":"c79ca805.386358","type":"delay","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"2","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":680,"y":120,"z":"6480e14.f9b7f2","wires":[["28d51638.d72aea"]]},{"id":"28d51638.d72aea","type":"debug","name":"","active":true,"console":"false","complete":"false","x":832,"y":175,"z":"6480e14.f9b7f2","wires":[]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment