List of sections within microbit module?
Posted: Wed Nov 01, 2017 9:06 pm
Most Micropython code examples start with the line
from microbit import *
...followed by a few lines of code which don't come anywhere close to filling up the limited code memory space of the Micro:Bit.
My understanding (which could be wrong) is that importing * results in all of the support code for all of the standard features of the Micro: Bit being included in your output code, even if your program does not use ninety percent of it.
I've already run into problems with this, having written some code which, together with the full imported block of support code, managed to exceed the size of the available code memory.
The solution to this would seem to be to import only those parts from microbit which my code needs, but, here's my problem, I can't find a list of Microbit sub-modules anywhere. I therefore don't know which modules to import and which to leave out. In fact, I don't even know their names.
In the case of the over-ambitious project referred to, I correctly guessed that one of the sub-parts would be called 'display' and so I replaced
from microbit import *
with
from microbit import display
This was accepted, but then the upload threw up an error at the first line containing a pinx.digital_write (n) statement, so presumably there's also an I/O subsection in microbit which I have to import as well, in order for pin read / pin write statements to work. But what is it called, and where can I find the names and details of all the other 'importable' parts of 'microbit' so I can choose which ones to import and which ones to leave out?
from microbit import *
...followed by a few lines of code which don't come anywhere close to filling up the limited code memory space of the Micro:Bit.
My understanding (which could be wrong) is that importing * results in all of the support code for all of the standard features of the Micro: Bit being included in your output code, even if your program does not use ninety percent of it.
I've already run into problems with this, having written some code which, together with the full imported block of support code, managed to exceed the size of the available code memory.
The solution to this would seem to be to import only those parts from microbit which my code needs, but, here's my problem, I can't find a list of Microbit sub-modules anywhere. I therefore don't know which modules to import and which to leave out. In fact, I don't even know their names.
In the case of the over-ambitious project referred to, I correctly guessed that one of the sub-parts would be called 'display' and so I replaced
from microbit import *
with
from microbit import display
This was accepted, but then the upload threw up an error at the first line containing a pinx.digital_write (n) statement, so presumably there's also an I/O subsection in microbit which I have to import as well, in order for pin read / pin write statements to work. But what is it called, and where can I find the names and details of all the other 'importable' parts of 'microbit' so I can choose which ones to import and which ones to leave out?