Tilt the micro:bit to change color.
Continuously store the value of the x
axis of the accelerator in the variable movement
. Since the accelerator gives readings in the range -1023
to 1023
, use a map to convert it to the range 0
to 100
and store it in the hue
variable. Set the hue of the RGB LED A
to the value of the hue
variable.
let movement = 0 let hue = 0 basic.forever(function () { movement = input.acceleration(Dimension.X) hue = Math.map(movement, -1023, 1023, 0, 100) sb.setRgbLedColorHSB(sb.rgbLed(SBRgbLed.RgbLedA), hue, 100, 100) })
If using micro:bit for the first time, follow this setup.