I am a newbie both to python mu and microbit (although a long time ago I used to program in ALGOL and FORTRAN before basic came along).
I believe that I have made a stupid mistake.
In the https://microbit-micropython.readthedocs.io/en/latest/ a search for light_level
gave an entry entry microbit.display.read_light_level()
I have written a simple program
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
from microbit import *
import microbit
temp = microbit.temperature()
print(temp)
microbit.display.scroll(str(temp))
print(microbit.display.read_light_level())
llevel = microbit.display.read_light_level()
print(llevel)
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
When run this gives the output (when no torch shone on the microbit)
>>> 20
0
MicroPython v1.9.2-34-gd64154c73 on 2017-09-01; micro:bit v1.0.1 with nRF51822
Type "help()" for more information.
When run again this gives the output (when a torch shone on the microbit)
>>> 20
230
MicroPython v1.9.2-34-gd64154c73 on 2017-09-01; micro:bit v1.0.1 with nRF51822
Type "help()" for more information.
>>>
obviously
1 The temperature (20) is output correctly on both REPL and the display
2 The value 0 or 230 printed are the light levels.
3 Nothing is output to the display after 20 is printed out
Now does anyone know how to get the value light-level into a variable?
Is Light Level operational in mu
Re: Is Light Level operational in mu
It looks like your code does put the light level into a variable "llevel", but the code never actually puts that on the screen? Sounds like you're missing
(btw, I think you don't need the "str" anymore, i believe they made it so display.scroll/show convert automatically)
Code: Select all
microbit.display.scroll(str(llevel))