By reversing the LEDs of the screen to become an input, the LED screen works as a basic light sensor, allowing you to detect ambient light.

Use the display’s LEDs in reverse-bias mode to sense the amount of light falling on the display. Returns an integer between 0 and 255 representing the light level, with larger meaning more light.

from microbit import *

while True:
    val = display.read_light_level()
    display.scroll(val)
    sleep(5000)

DIY

Program the micro:bit to scroll the message:

  • « NIGHT » if the amout of light is weak (under the value 5);
  • « SUNLIGHT » if the amount of light is strong (more than the value 100);
  • « DAY » if the amount of light is enough (between the values 5 and 100).

Help: the instruction else if is coded elif.