What is the best way to blink an led multiple times

1,591 views
Skip to first unread message

Paul Woodard

unread,
Aug 30, 2016, 8:39:59 AM8/30/16
to Node-RED
I have a temperature measuring setup (who doesn't) but it is in a box and I want an LED to flash when it takes a reading. Here are the two flows I came up with, but I wonder which is 'better' or if there is even a 'better' solution.
Note, the two gpio pins just go to an LED with both green and amber and I wanted to see which looked better.


[{"id":"2b126ce.fd4ed94","type":"inject","z":"f6632273.099ce","name":"","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"x":178,"y":264,"wires":[["f6a02c9a.095fd","1a984dcb.e567b2","1e84bae4.e17b45","5f918ab1.a06e74","c2382799.3dc7d8","2158b1d9.dea74e"]]},{"id":"4694badf.b96b44","type":"rpi-gpio out","z":"f6632273.099ce","name":"","pin":"16","set":"","level":"0","out":"out","x":824,"y":261,"wires":[]},{"id":"209ff43.fdf600c","type":"rpi-gpio out","z":"f6632273.099ce","name":"","pin":"15","set":"","level":"0","out":"out","x":878,"y":389,"wires":[]},{"id":"f6a02c9a.095fd","type":"trigger","z":"f6632273.099ce","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"250","extend":false,"units":"ms","reset":"","name":"","x":602,"y":261,"wires":[["4694badf.b96b44"]]},{"id":"1a984dcb.e567b2","type":"delay","z":"f6632273.099ce","name":"","pauseType":"delay","timeout":".5","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":357,"y":68,"wires":[["f6a02c9a.095fd"]]},{"id":"1e84bae4.e17b45","type":"delay","z":"f6632273.099ce","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":360,"y":111,"wires":[["f6a02c9a.095fd"]]},{"id":"385f3dec.c7a0c2","type":"function","z":"f6632273.099ce","name":"send 5 1's","func":"var msg1 = { payload: 1 };\nvar msg2 = { payload: 1 };\nvar msg3 = { payload: 1 };\nreturn [  msg1, msg2, msg3  ];","outputs":"3","noerr":0,"x":307,"y":388,"wires":[["cfc31928.303ce8"],["cfc31928.303ce8"],["cfc31928.303ce8"]]},{"id":"f3c695b3.0c3968","type":"inject","z":"f6632273.099ce","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":150,"y":387,"wires":[["385f3dec.c7a0c2"]]},{"id":"cfc31928.303ce8","type":"delay","z":"f6632273.099ce","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":475,"y":390,"wires":[["d1e1c2bf.2e1e4","4d5a879c.b2a578"]]},{"id":"d1e1c2bf.2e1e4","type":"trigger","z":"f6632273.099ce","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"250","extend":false,"units":"ms","reset":"","name":"","x":709,"y":389,"wires":[["209ff43.fdf600c"]]},{"id":"4d5a879c.b2a578","type":"delay","z":"f6632273.099ce","name":"","pauseType":"delay","timeout":"0.5","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":597,"y":345,"wires":[["d1e1c2bf.2e1e4"]]},{"id":"5f918ab1.a06e74","type":"delay","z":"f6632273.099ce","name":"","pauseType":"delay","timeout":"1.5","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":366,"y":152,"wires":[["f6a02c9a.095fd"]]},{"id":"c2382799.3dc7d8","type":"delay","z":"f6632273.099ce","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":360,"y":194,"wires":[["f6a02c9a.095fd"]]},{"id":"2158b1d9.dea74e","type":"delay","z":"f6632273.099ce","name":"","pauseType":"delay","timeout":"2.5","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":367,"y":235,"wires":[["f6a02c9a.095fd"]]}]

Dave C-J

unread,
Aug 30, 2016, 11:30:18 AM8/30/16
to node...@googlegroups.com
I like the second... could be simplified slightly :-)

[{"id":"54e1b144.e373b","type":"inject","z":"896b28a8.437658","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":88,"y":1684,"wires":[["2deda12b.95189e"]]},{"id":"2deda12b.95189e","type":"function","z":"896b28a8.437658","name":"send 5 msgs","func":"\nreturn [[msg,msg,msg,msg,msg]];","outputs":1,"noerr":0,"x":253,"y":1685,"wires":[["7170eb90.5e9a64"]]},{"id":"7170eb90.5e9a64","type":"delay","z":"896b28a8.437658","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"2","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":424,"y":1685,"wires":[["15a451dd.547a6e"]]},{"id":"15a451dd.547a6e","type":"trigger","z":"896b28a8.437658","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"250","extend":false,"units":"ms","reset":"","name":"","x":600,"y":1685,"wires":[["d76b18b5.6975d8"]]},{"id":"d76b18b5.6975d8","type":"debug","z":"896b28a8.437658","name":"","active":true,"console":"false","complete":"payload","x":776,"y":1685,"wires":[]}]

Cory Guynn

unread,
Aug 30, 2016, 11:52:07 AM8/30/16
to Node-RED


I tried a more JavaScript approach using setTimeout and setInterval to send the triggers.


// trigger frequency
var trigger = setInterval(function(){
    node.send(msg);
}, 500);

// trigger total time
setTimeout(function(){
    clearInterval(trigger);
},2000);

return null;





[{"id":"5a8cf798.a015c8","type":"inject","z":"1285db34.e8ce45","name":"","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"x":88.66665649414062,"y":50,"wires":[["288623b4.9f20ac"]]},{"id":"288623b4.9f20ac","type":"function","z":"1285db34.e8ce45","name":"trigger frequency","func":"\n// trigger frequency\nvar trigger = setInterval(function(){\n    node.send(msg);\n}, 500);\n\n// trigger total time\nsetTimeout(function(){\n    clearInterval(trigger);\n},2000);\n\nreturn null;\n\n","outputs":1,"noerr":0,"x":158.66665649414062,"y":97.33332824707031,"wires":[["c06bdfab.ec5bf"]]},{"id":"41c7cf18.a2072","type":"debug","z":"1285db34.e8ce45","name":"","active":true,"console":"false","complete":"false","x":331.6666259765625,"y":187.66666412353516,"wires":[]},{"id":"c06bdfab.ec5bf","type":"trigger","z":"1285db34.e8ce45","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"250","extend":false,"units":"ms","reset":"","name":"","x":238.6666259765625,"y":140.33330535888672,"wires":[["41c7cf18.a2072"]]}]


Zenofmud

unread,
Aug 30, 2016, 2:34:40 PM8/30/16
to node...@googlegroups.com
Ohhh I didn’t know you could send the same message multiple times!! And this is simpler. I learn something new every day :>)

On Aug 30, 2016, at 11:30 AM, Dave C-J <dce...@gmail.com> wrote:

I like the second... could be simplified slightly :-)

[{"id":"54e1b144.e373b","type":"inject","z":"896b28a8.437658","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":88,"y":1684,"wires":[["2deda12b.95189e"]]},{"id":"2deda12b.95189e","type":"function","z":"896b28a8.437658","name":"send 5 msgs","func":"\nreturn [[msg,msg,msg,msg,msg]];","outputs":1,"noerr":0,"x":253,"y":1685,"wires":[["7170eb90.5e9a64"]]},{"id":"7170eb90.5e9a64","type":"delay","z":"896b28a8.437658","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"2","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":424,"y":1685,"wires":[["15a451dd.547a6e"]]},{"id":"15a451dd.547a6e","type":"trigger","z":"896b28a8.437658","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"250","extend":false,"units":"ms","reset":"","name":"","x":600,"y":1685,"wires":[["d76b18b5.6975d8"]]},{"id":"d76b18b5.6975d8","type":"debug","z":"896b28a8.437658","name":"","active":true,"console":"false","complete":"payload","x":776,"y":1685,"wires":[]}]

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
For more options, visit https://groups.google.com/d/optout.

Zenofmud

unread,
Aug 30, 2016, 2:38:25 PM8/30/16
to node...@googlegroups.com
I love this forum, what great help! Two great ‘better’ solutions!
Reply all
Reply to author
Forward
0 new messages