Trying to read an analog voltage on either pin 0, 1, or 2. Can do this in MakeCode but want to do it in Python instead. When I do it in MakeCode, and then I switch the editor to get the equivalent Python code, that code looks like this:
When I paste that code into the Python editor, it can’t find ‘basic’ or ‘pins’. I’m assuming those are needed imports but I can’t figure out how to resolve that problem.
The different version, called MicroPython, has different names for the commands, which are described here: https://microbit-micropython.readthedocs.io/en/v2-docs/. In the Python-only (MicroPython) version it would look like this:
from microbit import *
while True:
display.show(pin0.read_analog())
The MakeCode Python code only works in MakeCode. If you are pasting the code into anyplace else, it’s probably expecting the MicroPython approach. That is, any place other than makecode.microbit.org is probably MicroPython and you need to use the approaches described here: https://microbit-micropython.readthedocs.io/ .