get_mode for micro:bit pins with analog read and write
Posted: Sat Aug 22, 2020 4:32 pm
I can't find the documentation for the BBC micro:bit MicroPython's get_mode() method on the pins. It appears to be set all the time to a useful value apart from for read_analog() where it returns unused for some reason?
There are some tests in https://github.com/bbcmicrobit/micropyt ... st_pins.py which expect this behaviour but they do not document why that result is expected. They also suggest that write_analog mode varies with the value which I've just confirmed too:
Code: Select all
MicroPython v1.9.2-34-gd64154c73 on 2017-09-01; micro:bit v1.0.1 with nRF51822
Type "help()" for more information.
>>>
>>> from microbit import *
>>> pin2.get_mode()
'read_digital'
>>> pin2.write_digital(1)
>>> pin2.get_mode()
'write_digital'
>>> pin2.write_analog(123)
>>> pin2.get_mode()
'write_analog'
>>> pin2.is_touched()
False
>>> pin2.get_mode()
'touch'
>>> pin2.read_analog()
223
>>> pin2.get_mode()
'unused'
Code: Select all
>>> pin2.write_analog(123)
>>> pin2.get_mode()
'write_analog'
>>> pin2.write_analog(0)
>>> pin2.get_mode()
'unused'