2. Other Projects‎ > ‎Micro:Bit‎ > ‎

Am I up or down?

posted 17 Dec 2016, 07:21 by Andy Lakin-Hall

Here's a second script to detect whether the microbit is lying flat or lifted up.

This script uses a variable, which I have called "pitch"

The purple block rotation (°) pitch won't drop into the IF block. But the variable I defined will.

By experimenting, I discovered that the pitch of the microbit can be sensed from 0° to 90° up and then -90° down, giving a full 180° of rotation. Roll works in a similar way; flat is 0°. rolls to the right count up to 90°, while rolls to the left count down to -90°.

The IF block can be found in the blue LOGIC tab. It can be switched to IF/ELSE by clicking on the blue gear.

The pattern of LEDs is defined from the teal BASIC tab, and I have drawn an arrow pointing up, and a circular target.