JasonV
23 September 2021 15:00
1
Hello my name is Jason,
I have a question about how to set a push button as on/off function.
I already started to construct a push button which functions quite nicely as long as I push and release the button. It then changes from 1 to 0. But my intention that I very much would like to do is to turn on and off the LED light by PRESSING the button instead of releasing.
Kind regards,
Jason
Is it a physical button connected to a GPIO or a Node-RED dashboard button?
Can you paste a picture of your flow?
Gunner
23 September 2021 21:21
3
Near as I can tell, Node-Red's ui_button
only "triggers" on release - as I discovered when working on this topic...
Actually, it doesn't trigger on the "press", rather it triggers on the "release"... strange that I never noted that before. It clearly detects the press visually, so why not trigger on both?
However there are some solutions - such as creating your own button ...
Hello Ali ..
you could use the ui_template node and take advantage of javascripts mousedown and mouseup eventlisteners on the button.
Example Flow
[{"id":"81fc920712f2501c","type":"ui_template","z":"4895ea10b4ee9ead","group":"e68f0343d6bbfce5","name":"","order":0,"width":0,"height":0,"format":"<button id=\"myBtn\">Click Me</button>\n\n<script>\n(function(scope) {\n\nlet myBtn = document.getElementById('myBtn')\n\nmyBtn.addEventListener('mousedown', e => {\nscope.send({payload: 1})\n});\n\nmyB…
edje11
24 September 2021 09:09
4
Hi Jason,
Have a look at the node-red-contrib-toggle
It will do the job.
JasonV
24 September 2021 11:15
5
Dear Cymplecy
Yes it is a physical button connected to a GPIO of a raspberry pi( Ground -> GPIO 26) and a LED to the pins ( ground -> GIO 16)
When i push the button the state from the button change to 0 en the led turns off and when i release the button the state change back to 1
( when I press the push button )
( when I release the push button )
I would like that the LED stay on when the push button is released and goes back out when I press again
Try this:
and then make sure that the topic of this:
is set to: toggle
Ed
JasonV
24 September 2021 11:58
7
I tried but then the led doesn't work anymore it just stays on
Settings Input
Toggle node
Add this before the Toggle node:
Edit it to look like this:
Ed
system
Closed
8 October 2021 13:43
11
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.