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":[]}]
dceejay

Flow Info

created 2 years, 5 months ago

Node Types

Core
  • debug (x1)
  • delay (x1)
  • function (x1)
  • inject (x1)

Tags

  • flash
  • pulse
  • LED
  • loop
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option