Is Light Level operational in mu

Questions and discussion about running MicroPython on a micro:bit board.
Target audience: MicroPython users with a micro:bit.
Post Reply
Laurie
Posts: 1
Joined: Wed Jun 19, 2019 11:25 pm

Is Light Level operational in mu

Post by Laurie » Thu Jun 20, 2019 9:12 pm

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. :o

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?

User avatar
jimmo
Posts: 520
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia

Re: Is Light Level operational in mu

Post by jimmo » Fri Jun 21, 2019 12:00 am

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

Code: Select all

microbit.display.scroll(str(llevel))
(btw, I think you don't need the "str" anymore, i believe they made it so display.scroll/show convert automatically)

Post Reply