# Node always sends a "1" for 5 seconds and then a "0" for 5 seconds

**URL:** <https://discourse.nodered.org/t/node-always-sends-a-1-for-5-seconds-and-then-a-0-for-5-seconds/19518>\
**Category:** General\
**Created:** [23 December 2019 19:54 UTC](https://discourse.nodered.org/t/node-always-sends-a-1-for-5-seconds-and-then-a-0-for-5-seconds/19518 "2019-12-23T19:54:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![seppel1078](https://avatars.discourse-cdn.com/v4/letter/s/e8c25b/32.png) [@seppel1078](https://discourse.nodered.org/u/seppel1078)\
**Post date:** [23 December 2019 19:54 UTC](https://discourse.nodered.org/t/node-always-sends-a-1-for-5-seconds-and-then-a-0-for-5-seconds/19518/1 "2019-12-23T19:54:24Z")

</div>

Hi there,

I need a simple thing, but I kind of stand on the tube.

I just need a node that throws a "1" and then a "0" (or true/false) every 5 seconds. I tried the trigger, unfortunately I can only set the time length from "1" but not how long the "0" comes.

the background is I want to have 2 GPIO pins alternately output a "1" and the other a "0" alternately.

It's totally easy .....

Greetings Volker

---

<div class="post-metadata">

**Author:** ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)\
**Post date:** [23 December 2019 20:16 UTC](https://discourse.nodered.org/t/node-always-sends-a-1-for-5-seconds-and-then-a-0-for-5-seconds/19518/2 "2019-12-23T20:16:57Z")

</div>

This is one method. Adjust the time and add a second output

```auto
[{"id":"1487b85e.3df798","type":"ui_led","z":"14f630f.3ecfecf","group":"6d162e99.278f3","order":2,"width":0,"height":0,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"red","value":"0","valueType":"num"},{"color":"green","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"name":"","x":430,"y":60,"wires":[]},{"id":"78e813de.89ae0c","type":"inject","z":"14f630f.3ecfecf","name":"","topic":"","payload":"1","payloadType":"num","repeat":".25","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":60,"wires":[["38e8476d.5d8358"]]},{"id":"38e8476d.5d8358","type":"function","z":"14f630f.3ecfecf","name":"LED","func":"let z = msg.payload;\nlet y = flow.get('led');\nif (y == 'red'){\n flow.set('led','green');\n msg.payload = 0;\n node.status({fill:\"red\",shape:\"dot\",text:\"LED \" + y});\n return msg;\n} \nif (y == 'green') {\n flow.set('led','red');\n msg.payload = 1;\n node.status({fill:\"green\",shape:\"ring\",text:\"LED \" + y});\n return msg;\n}\n\nflow.set('led','red');\n\nreturn msg;","outputs":1,"noerr":0,"x":250,"y":60,"wires":[["1487b85e.3df798","375b28d8.530428"]]},{"id":"375b28d8.530428","type":"mqtt out","z":"14f630f.3ecfecf","name":"LED","topic":"LED","qos":"0","retain":"true","broker":"9b49824b.ebaf5","x":430,"y":120,"wires":[]},{"id":"6d162e99.278f3","type":"ui_group","z":"","name":"Home","tab":"fe965871.9140d8","disp":false,"width":"6","collapse":false},{"id":"9b49824b.ebaf5","type":"mqtt-broker","z":"","name":"four","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"fe965871.9140d8","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![seppel1078](https://avatars.discourse-cdn.com/v4/letter/s/e8c25b/32.png) [@seppel1078](https://discourse.nodered.org/u/seppel1078)\
**Post date:** [23 December 2019 20:45 UTC](https://discourse.nodered.org/t/node-always-sends-a-1-for-5-seconds-and-then-a-0-for-5-seconds/19518/3 "2019-12-23T20:45:52Z")

</div>

Thank you, it works!

I have installed an additional inverter so that I save the second output. Not nice but it works.

```auto
[{"id":"9c54e5eb.1c70f","type":"tab","label":"Flow 5","disabled":false,"info":""},{"id":"41570a4c.1cecc4","type":"InvertUltimate","z":"9c54e5eb.1c70f","name":"Invert","x":484,"y":140,"wires":[["8ab7b53e.09ed1"]]},{"id":"53da9b34.86a64c","type":"inject","z":"9c54e5eb.1c70f","name":"","topic":"","payload":"1","payloadType":"num","repeat":"5","crontab":"","once":false,"onceDelay":0.1,"x":174,"y":80,"wires":[["f3c06638.cf3fe8"]]},{"id":"f3c06638.cf3fe8","type":"function","z":"9c54e5eb.1c70f","name":"LED","func":"let z = msg.payload;\nlet y = flow.get('led');\nif (y == 'red'){\n flow.set('led','green');\n msg.payload = 0;\n node.status({fill:\"red\",shape:\"dot\",text:\"LED \" + y});\n return msg;\n} \nif (y == 'green') {\n flow.set('led','red');\n msg.payload = 1;\n node.status({fill:\"green\",shape:\"ring\",text:\"LED \" + y});\n return msg;\n}\n\nflow.set('led','red');\n\nreturn msg;","outputs":1,"noerr":0,"x":334,"y":80,"wires":[["41570a4c.1cecc4","4587f900.a1724"]]},{"id":"4587f900.a1724","type":"debug","z":"9c54e5eb.1c70f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":650,"y":80,"wires":[]},{"id":"8ab7b53e.09ed1","type":"debug","z":"9c54e5eb.1c70f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":650,"y":140,"wires":[]}]

```

Greetings Volker

---

<div class="post-metadata">

**Author:** ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)\
**Post date:** [23 December 2019 22:24 UTC](https://discourse.nodered.org/t/node-always-sends-a-1-for-5-seconds-and-then-a-0-for-5-seconds/19518/4 "2019-12-23T22:24:01Z")

</div>

Played with it a bit, try this

```auto
[{"id":"14f630f.3ecfecf","type":"tab","label":"Alive","disabled":false,"info":""},{"id":"1487b85e.3df798","type":"ui_led","z":"14f630f.3ecfecf","group":"6d162e99.278f3","order":2,"width":0,"height":0,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"red","value":"0","valueType":"num"},{"color":"green","value":"1","valueType":"num"}],"allowColorForValueInMessage":false,"name":"","x":490,"y":60,"wires":[]},{"id":"78e813de.89ae0c","type":"inject","z":"14f630f.3ecfecf","name":"","topic":"","payload":"1","payloadType":"num","repeat":"1","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":60,"wires":[["38e8476d.5d8358"]]},{"id":"38e8476d.5d8358","type":"function","z":"14f630f.3ecfecf","name":"LED","func":"let z = msg.payload;\nlet y = flow.get('led');\nvar msg1 = { payload: 0};\nvar msg2 = { payload: 1};\nvar msg3 = { payload: 0}\n\nif (y == 'red'){\n flow.set('led','green');\n msg3 = { payload: 0}\n node.status({fill:\"red\",shape:\"dot\",text:\"LED \" + y});\n return [msg1, msg2, msg3];\n} \nif (y == 'green') {\n flow.set('led','red');\n msg3 = { payload: 1}\n node.status({fill:\"green\",shape:\"ring\",text:\"LED \" + y});\n return [msg2, msg1, msg3];\n}\n\nflow.set('led','red');\n\nreturn msg;","outputs":3,"noerr":0,"x":250,"y":60,"wires":[["1487b85e.3df798","375b28d8.530428","f3dfa914.8f09a8"],["3eb65a92.980abe"],["ca535ab9.78c458"]]},{"id":"375b28d8.530428","type":"mqtt out","z":"14f630f.3ecfecf","name":"LED","topic":"LED","qos":"0","retain":"true","broker":"9b49824b.ebaf5","x":490,"y":100,"wires":[]},{"id":"f3dfa914.8f09a8","type":"rpi-gpio out","z":"14f630f.3ecfecf","name":"","pin":"33","set":true,"level":"0","freq":"","out":"out","x":500,"y":160,"wires":[]},{"id":"3eb65a92.980abe","type":"rpi-gpio out","z":"14f630f.3ecfecf","name":"","pin":"35","set":true,"level":"0","freq":"","out":"out","x":500,"y":220,"wires":[]},{"id":"ca535ab9.78c458","type":"rpi-gpio out","z":"14f630f.3ecfecf","name":"","pin":"37","set":true,"level":"0","freq":"","out":"out","x":500,"y":280,"wires":[]},{"id":"6d162e99.278f3","type":"ui_group","z":"","name":"Home","tab":"fe965871.9140d8","disp":false,"width":"6","collapse":false},{"id":"9b49824b.ebaf5","type":"mqtt-broker","z":"","name":"four","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"fe965871.9140d8","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![seppel1078](https://avatars.discourse-cdn.com/v4/letter/s/e8c25b/32.png) [@seppel1078](https://discourse.nodered.org/u/seppel1078)\
**Post date:** [23 December 2019 23:31 UTC](https://discourse.nodered.org/t/node-always-sends-a-1-for-5-seconds-and-then-a-0-for-5-seconds/19518/5 "2019-12-23T23:31:15Z")

</div>

Good work. That is exactly what I was looking for

Greetings Volker
