Not entirely. You need to specify "Pin.IN" so MicroPython knows you are dealing with an input pin, but adding PULL_UP or PULL_DOWN is entirely optional.I get that you need to add Pin.IN when creating the pin in micropython and that you also need to add the internal resistor (PULL_UP or PULL_DOWN)
With most electronic devices there are no internal pull-up or pull-downs so a button input would need to be as below to give a reliable high or low signal -
Code:
___________ ___________ | | | | --.----| +V | --.----| +V | .|. | | | | | | | | | _|O | | |_| | | |_| | | | | | |O | | | | | | | | }--->| INPUT | }--->| INPUT | | | | | | | _|O | | .|. | | |_| | | | | | | |O | | |_| | | | | | | | | --^----| 0V | --^----| 0V | |___________| |___________|
Code:
___________ ___________ | | | | -|---.- +V | --.----|----- +V | | .|. | | | | | | | | _|O | | | |_| | |_| | | | | | |O | | | | | | | | .--->|---^- IN | `--->|---.- IN | | | | | | | _|O | | | .|. | |_| | | | | | | |O | | | |_| | | | | | | | --^----|----- 0V | -|---^- 0V | |___________| |___________|
Most will use "Pin.PULL_UP" and "Pin.PULL_DOWN" because it makes things easier and cheaper, saves on needing those external resistors and having to fit them, which may become a significant saving if you have more than one button.
Statistics: Posted by hippy — Thu Aug 01, 2024 10:50 am