Passo 1: Projeto
O que é?
Make a tool for making sure pictures, shelves or work surfaces are level. The new micro:bit's built-in speaker makes it easy to improve your spirit level with audio feedback.
O que você aprenderá
- 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
- 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.
O que você precisa
- Um micro:bit
- Editor MakeCode ou Python
- bateria (opcional)
Passo 2: É hora de programar
Passo 3: Vamos melhorar
- 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?