I want to code using a pull-up resistor. However, I don’t know the correct coding. I tried it, but I would like to know if the following coding is correct.
Connect the button switch to pin 3 and GND to read the ON/OFF status of the switch.
import mraa
import time
gpio_sw = mraa.Gpio(3)
gpio_sw.inputMode(mraa.MODE_IN_ACTIVE_HIGH)
time.sleep(1)
gpio_sw.dir(mraa.DIR_IN)
while True:
result = gpio_sw.read()
print(result)
time.sleep(0.1)
Thank you for your support.