Blinking LEDS on Raspberry Pi
A big Thank You to Nathanaël Lécaudé from the Google Group for providing the clever bits of this flow. The discussion can be found at https://groups.google.com/forum/#!topic/node-red/HwtD1suZuOM
The original flow can be found at http://flows.nodered.org/flow/dd353d32ce7e8b266470
I wanted to be able to flash some LEDs for a short period of time on receiving an input.
The clever bit here is the function. It responds to the inputs 'on' and 'off' When you send it on it will output 0 and 1 alternatively. Off will stop it.
The LED is wired to pin 12 on the Raspberry Pi. The flow will work with both the B and B+.
[{"id":"4ccd3e4c.b98bf","type":"trigger","op1":"1","op2":"0","op1type":"val","op2type":"val","duration":"250","extend":"false","units":"ms","name":"","x":356,"y":161,"z":"9000de2.0d9bb2","wires":[["16ddf53a.98e803","21f85dc7.31042a"]]},{"id":"16ddf53a.98e803","type":"function","name":"","func":"if (msg.payload == \"off\")\n\tcontext.state = 0;\nif (msg.payload == \"on\")\n\tcontext.state = 1;\n\nif (context.state == 1)\n{\n\tif (msg.payload == 0)\n\t\treturn msg;\n\telse\n\t\treturn;\n}\nelse\n\treturn;","outputs":1,"x":472,"y":311,"z":"9000de2.0d9bb2","wires":[["99d5a96a.8fc36"]]},{"id":"99d5a96a.8fc36","type":"delay","name":"","pauseType":"delay","timeout":"250","timeoutUnits":"milliseconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":700,"y":312,"z":"9000de2.0d9bb2","wires":[["4ccd3e4c.b98bf"]]},{"id":"61bafd4.4f5c604","type":"switch","name":"","property":"payload","rules":[{"t":"eq","v":"on"},{"t":"eq","v":"off"}],"checkall":"true","outputs":2,"x":137,"y":227,"z":"9000de2.0d9bb2","wires":[["16ddf53a.98e803","4ccd3e4c.b98bf"],["16ddf53a.98e803"]]},{"id":"21f85dc7.31042a","type":"rpi-gpio out","name":"LED","pin":"12","set":"","level":"0","out":"out","x":599,"y":130,"z":"9000de2.0d9bb2","wires":[]},{"id":"1b27b598.b0b562","type":"inject","name":"On","topic":"","payload":"on","payloadType":"string","repeat":"","crontab":"","once":false,"x":77,"y":113,"z":"9000de2.0d9bb2","wires":[["61bafd4.4f5c604","4e642f9c.8f4e58"]]},{"id":"4e642f9c.8f4e58","type":"delay","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":231,"y":60,"z":"9000de2.0d9bb2","wires":[["58285cdd.9f4914"]]},{"id":"58285cdd.9f4914","type":"change","action":"replace","property":"payload","from":"","to":"off","reg":false,"name":"Switch off","x":398,"y":56,"z":"9000de2.0d9bb2","wires":[["61bafd4.4f5c604"]]}]