I want to use a slider button of 3 pins.
Actually I'm using 2 of it, like the schematic below:
simulate this circuit – Schematic created using CircuitLab
My code is:
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
green_led = 21
GPIO.setup(green_led, GPIO.IN)
while True:
green_led_state = GPIO.input(green_led)
print('#### - ',green_led_state, ' - ####')
In my opinion whith this code, if don't touch my slider always have to print the same value (1 or 0) depending of its position. And if I change the position of the slider, print the other value all the time.
But now, without touching nothing is printing 0 and 1 randomly (I think randomly). Why this? Why some times has current and sometimes not?
Thanks