On Shake

Register an event handler that will execute whenever the user shakes the BBC micro:bit; in the web browser, click the button labelled "SHAKE" under the simulator to generate a shake event.

Block Editor

Touch Develop

input → on shake do
add code here
end

Example: random number

The following example displays a number from 0-9 on the screen when you shake the BBC micro:bit.
input → on shake do
var x := math → random(10)
basic → show number(x, 100)
end

Example: rock, paper, scissors

The following example shows one of three images (rock, paper, or scissors) when you shake the BBC micro:bit.
input → on shake do
var img := image → create image()
img → show image(5 * math → random(3))
end

Lessons

See also