Stopwatch function

Simple stopwatch function.

on = green LED = counting

off = red LED = stop + reset

Can't be more simple.

Uses node-red-contrib-ui-digital-display

[{"id":"25edf2fcecf7ac51","type":"ui_switch","z":"e9a8c68eda773680","name":"Power on/off","label":"","tooltip":"","group":"9a6254e6.c472c8","order":13,"width":2,"height":1,"passthru":false,"decouple":"false","topic":"","topicType":"str","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","animate":true,"className":"","x":790,"y":1160,"wires":[["059248c5259e5378"]]},{"id":"dcb2203049fe0ea6","type":"ui_digital_display","z":"e9a8c68eda773680","name":"","group":"9a6254e6.c472c8","order":1,"width":"7","height":2,"digits":5,"decimals":"2","x":2020,"y":1200,"wires":[]},{"id":"649e0c9271602ca8","type":"inject","z":"e9a8c68eda773680","name":"every 1 second","props":[{"p":"payload"}],"repeat":"1","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":900,"y":1100,"wires":[["a07e6c57b1a1c8c0"]]},{"id":"a07e6c57b1a1c8c0","type":"switch","z":"e9a8c68eda773680","name":"flow.clock_state == \"run\" ?","property":"clock_state","propertyType":"flow","rules":[{"t":"eq","v":"run","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1140,"y":1100,"wires":[["4f71dedcce348bad"]]},{"id":"cdd0a96f03d825dd","type":"change","z":"e9a8c68eda773680","name":"set clock_value to 0","rules":[{"t":"set","p":"clock_value","pt":"flow","to":"0","tot":"num"},{"t":"set","p":"clock_state","pt":"flow","to":"stop","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1190,"y":1200,"wires":[["56b85be367b59317"]]},{"id":"4f71dedcce348bad","type":"function","z":"e9a8c68eda773680","name":"decrement flow.clock_value","func":"let clock_value = flow.get(\"clock_value\") || 0;\n\nclock_value++; \n\nif (clock_value < 0) clock_value = 0;\n\nflow.set(\"clock_value\", clock_value);\n\nmsg.payload = clock_value;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1440,"y":1100,"wires":[["56b85be367b59317"]]},{"id":"56b85be367b59317","type":"function","z":"e9a8c68eda773680","name":"seconds to minute:seconds","func":"let secsDecimal = msg.payload;\n\nlet mins = Math.floor(secsDecimal/60);\nlet secs = secsDecimal % 60;\n\nmsg.payload = (mins + (secs / 100.0)).toFixed(2)\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1760,"y":1200,"wires":[["dcb2203049fe0ea6"]]},{"id":"11c3bf981a8b75cb","type":"function","z":"e9a8c68eda773680","name":"toggle flow.clock_state","func":"let clock_state = flow.get(\"clock_state\") || \"stop\";\n\nclock_state = clock_state === \"stop\" ? \"run\" : \"stop\";\n\nflow.set(\"clock_state\", clock_state );\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1460,"y":1140,"wires":[["56b85be367b59317"]]},{"id":"059248c5259e5378","type":"switch","z":"e9a8c68eda773680","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":990,"y":1160,"wires":[["efd8c7ef06c87dba"],["cdd0a96f03d825dd"]]},{"id":"efd8c7ef06c87dba","type":"change","z":"e9a8c68eda773680","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"run","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1180,"y":1140,"wires":[["11c3bf981a8b75cb"]]},{"id":"9a6254e6.c472c8","type":"ui_group","name":"Default","tab":"2043e431.1fd824","order":1,"disp":false,"width":"8","collapse":false},{"id":"2043e431.1fd824","type":"ui_tab","name":"ON TIME","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

Flow Info

Created 2 years, 4 months ago
Rating: 5 4

Owner

Actions

Rate:

Node Types

Core
  • change (x2)
  • function (x3)
  • inject (x1)
  • switch (x2)
Other

Tags

  • Stopwatch
  • timer
  • counting
  • count
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option