Using a 4 pin button I can get a 0/1 reading when I press/release the button.
But when I use a 2 pin button I get 1 when I press it but random 0 or 1 when I release it.
Can someone please explain how can I get a absolute 0 or 1 when I press and release the 2 pin button ?
I have included a labeled diagram of my breadboard.
But when I use a 2 pin button I get 1 when I press it but random 0 or 1 when I release it.
It's because you have the buttons wired differently. That particular 4 terminal push button has 4 terminals (the vertical pins are connected together internally and the switch pins are left to right). So referencing your 4 pin configuration, you have Digital Pin 2 tied to +5V through the resistor when the button is open and Pin 2 shorted to ground when the button is pressed. In the 2 pin configuration you have Digital Pin 2 floating (not connected to anything) when the button is open and when the button is pressed, tied to +5V through the resistor.
What you want to do is move the Digital Pin 2 wire to the red wire on the switch and connect the black switch wire to ground. This will give you the same results as the 4 pin configuration.
To insert images, one way is to put them on the internet somewhere as a .jpg file.
Then press the little image button above (2nd row, 2nd from left) and paste the url between
'bracket img bracket' and 'bracket /img bracket' that comes up.
Another way is to click Additional Options below and browse to the file you want to attach.
I don't know if files besides .jpg will display.