Skip to content

Aktivnost

Spirit level

Srednji | MakeCode, Python | LED zaslon, Mjerač ubrzanja, Zvuk | Booleova logika, Odabir, Relacijski operatori, Senzori

1. korak: Napravi

Što je to?

Izradite alat kako biste izradili fotografije, police ili radne površine. The new micro:bit's built-in speaker makes it easy to improve your spirit level with audio feedback.

Uvod

Vodič za kodiranje

Što ćeš naučiti

  • How to use the accelerometer sensor to measure angles
  • What 'pitch' and 'roll' are
  • How to combine sensor readings in two dimensions to find a level surface

Kako to radi

diagram showing pitch and roll on the micro:bit
  • The micro:bit's accelerometer can measure angles of tilt in two directions: up and down (pitch) and side to side (roll). This project uses this to show when the micro:bit is level on the LED display and by making a sound, which could be useful when hanging a picture or making a work surface.
  • A loop keeps the program constantly measuring the micro:bit's angle.
  • If the accelerometer measures an angle of tilt between +5 and -5 degrees of both pitch and roll, the micro:bit must be reasonably level. It then shows a tick on the LED display output and plays a musical tone.
  • To hear the tone attach headphones or a speaker to pin 0 and GND, or if you have a new micro:bit you will hear it on the built-in speaker.
  • If either the pitch or the roll is outside the range +5 to -5 degrees, it shows a cross on the LED display and stops the sound.

Što ti treba

  • micro:bit
  • Uređivač MakeCode ili Python
  • baterije (prema potrebi)

2. korak: Kodiraj

3. korak: Unaprijedi

  • Can you make the musical pitch change depending on the angle?
  • Could you code an LED 'bubble' that moves around the screen like a real spirit level?