Rpi-GPIO RGB LED random colours

A flow for the Raspberry Pi which requires a tri-colour LED and a button. The LED will switch to a random colour every 0.5 seconds, and the cycle can be toggled by pressing the button.

[{"id":"e1609adc.1e9f68","type":"rpi-gpio in","z":"d32c97b9.2cd368","name":"","pin":"16","intype":"tri","debounce":"100","read":true,"x":150,"y":189,"wires":[["a41646b0.5be9b8"]]},{"id":"a41646b0.5be9b8","type":"switch","z":"d32c97b9.2cd368","name":"","property":"payload","propertyType":"msg","rules":[{"t":"neq","v":"1","vt":"str"}],"checkall":"true","outputs":1,"x":369,"y":199,"wires":[["465a1366.7a43dc"]]},{"id":"4035f297.bfca0c","type":"ledborg","z":"d32c97b9.2cd368","name":"RGB LED","x":878,"y":303,"wires":[]},{"id":"296cb4ed.b171a4","type":"function","z":"d32c97b9.2cd368","name":"Random Colour Generation","func":"msg.payload = '#'+(0x1000000+(Math.random())*0xffffff).toString(16).substr(1,6);\n\nreturn msg","outputs":1,"noerr":0,"x":633,"y":290.5,"wires":[["4035f297.bfca0c"]]},{"id":"f1836665.7e4f3","type":"comment","z":"d32c97b9.2cd368","name":"Plug button into pin 8, right side","info":"Plug button into pin 8, right side","x":177,"y":58.5,"wires":[]},{"id":"7566af86.e98b28","type":"comment","z":"d32c97b9.2cd368","name":"Random Colour Selector for RGB LED","info":"Random Colour Selector for RGB LED","x":468,"y":58.5,"wires":[]},{"id":"fd018f2f.16eb98","type":"inject","z":"d32c97b9.2cd368","name":"Trigger","topic":"","payload":"","payloadType":"date","repeat":"0.5","crontab":"","once":true,"x":153,"y":269.5,"wires":[["3678bc9e.ccc72c"]]},{"id":"3678bc9e.ccc72c","type":"switch","z":"d32c97b9.2cd368","name":"","property":"ready","propertyType":"global","rules":[{"t":"true"}],"checkall":"true","outputs":1,"x":368,"y":283.5,"wires":[["296cb4ed.b171a4"]]},{"id":"b90e3089.8833e8","type":"inject","z":"d32c97b9.2cd368","name":"Initialise","topic":"","payload":"Program Initialised!","payloadType":"str","repeat":"","crontab":"","once":true,"x":164,"y":360.5,"wires":[["9871ff49.ce60c8"]]},{"id":"9871ff49.ce60c8","type":"function","z":"d32c97b9.2cd368","name":"Initialise","func":"context.global.ready = true;\n\nreturn msg;","outputs":1,"noerr":0,"x":374,"y":372.5,"wires":[[]]},{"id":"465a1366.7a43dc","type":"function","z":"d32c97b9.2cd368","name":"Switcher","func":"if (context.global.ready===true) {\n    context.global.ready = false;\n}\nelse {\n    context.global.ready = true;\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":572,"y":204.5,"wires":[[]]},{"id":"3757cff1.b29c38","type":"comment","z":"d32c97b9.2cd368","name":"Press button to toggle colour flash","info":"Press button to toggle colour flash","x":169,"y":100.5,"wires":[]}]
SulphuricGlue

Flow Info

created 11 months, 2 weeks ago

Node Types

Core
  • comment (x3)
  • function (x3)
  • inject (x2)
  • rpi-gpio in (x1)
  • switch (x2)
Other

Tags

  • rpi
  • rpi-gpio
  • gpio
  • rasperry
  • pi
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option