Been fooling around with node-red for a simple application to make a pushbutton that sends tcp commands to third party gear.

I've run into a problem with the GPI. I want to send different commands on every second pulse from a momentary switch on the GPI. Its normally 1 and changes to 0 on button press. Is there a way to insert a function to send 1 on the first pulse, 0 on the next, 1 on the third and so on?

I did it with this messy function I made up from various input from the link provided by DirkS and the idea of counting whether the button push/pull doublet I'm doing is even or odd. I suspect there must be an easier way...

Paste this into a function between the rp.gpio input (the button) and the rp.gpio output (the LED):