Skip to content


Get up!

Principiante | MakeCode, Python | Ecrã LED, Sensor de luz, Som | Iteração, Número & valor da posição , Seleção, Sensores

Passo 1: Faz tu mesmo

O que é isto?

Turn your micro:bit into a light-sensitive alarm to help you get up in the morning. You'll learn how to use infinite loops, and selection with comparison logic.

Estes dois vídeos mostram o que vais fazer e como programar:

Como é que funciona

  • The program uses the micro:bit’s LED display as a light sensor.
  • Selection ('if... else') and comparison logic (> 70) are used so that if the light level is above a certain amount, a sun icon appears and it makes a noise; else, it clears the screen.
  • If the light level is greater than (>) 70, a sun appears on the LED display, telling you it’s time to get up.
  • The program uses an infinite loop to keep sensing the light level.
  • You can adjust the threshold at which the sun appears. Use larger numbers to make it less sensitive to light, so the alarm only goes off when it's brighter - or smaller numbers to make it more sensitive to light.

Do que é que precisas

  • micro:bit (or use the simulator in the online editors)
  • Editor MakeCode ou Python
  • battery pack (optional but recommended)

Passo 2: Cria o teu código

Passo 3: Melhora-o

  • Change the alarm sound.
  • Replace the sun icon with motivational messages that can help you to start your day.