I'm designing an IoT smart button to turn on or off a light with an ESP-01. I want it to run off a battery so I'm using deep-sleep. The problem is I only want to have one button that you could press once to turn the light on, and either long press or press twice to turn the light off. With a ESP-12 and it's additional GPIO's the following circuit (which I found here) worked but it's doesn't work on the ESP-01 due to the limited GPIO pins.
So I looked around some more and found the following solution here
This circuit worked great except I don't really understand what's going on here. This would be okay (though I'd prefer to know why it works and what's going on) but sometimes the ESP-01 detects a long button press when there wasn't one. I've added a little delay to the code before it checks the button but it still isn't 100% reliable. I suspect it has something to do with the size of the capacitor or it's charge rate controlled by the resistors, but not knowing what exactly is going on I can't fix it.
So can anyone explain what's going on here (in the second circuit that is, I understand the first one)? Why is the capacitor making it so RST is only grounded temporarily and how is it affecting the grounding of GPIO 16 (16 in these diagram, but actually GPIO 2 on the ESP-01).
I tried mapping out this circuit in CircuitLab to see what was going on but I didn't know how to properly represent a GPIO pin so it didn't work.