Hi everyone,
I am a very beginner, don't be disgusted abut my question.
I am trying to count how many times a button is pressed.
I have setup a Rpi-gpio node on a pin and connected it to a function.
[{"id":"c74669a0.6a34f8","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"56056d7e.0a2584","type":"rpi-gpio in","z":"c74669a0.6a34f8","name":"LCD Scrolling","pin":"22","intype":"down","debounce":"250","read":false,"x":190,"y":160,"wires":[["24df9475.386c6c"]]},{"id":"48f45062.bbd3b","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":430,"y":160,"wires":[]},{"id":"24df9475.386c6c","type":"function","z":"c74669a0.6a34f8","name":"","func":"var count = msg.payload;\ncount++\n\nif (count >4)\n{ count==0\n}\n\n\nmsg.payload=count\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":350,"y":240,"wires":[["48f45062.bbd3b"]]}]
I wrote this function but is not giving me the expected result. My expectation was to see a message incrementing from 1 to 4 and then again from 1 to 4, and so on.
var count = msg.payload;
count++
if (count >4)
{ count==1
}
msg.payload=count
return msg;
I keep getting 2 message in sequence 2, 1
What I expect to get is: 1, 2, 3, 4 ... 1
I am not sure about what is wrong. Any help will be appreciated. Thank you