2016-03-26 00:47:20 +01:00
|
|
|
# On Gesture
|
|
|
|
|
2016-06-09 01:59:20 +02:00
|
|
|
Start an [event handler](/reference/event-handler) (part of the
|
|
|
|
program that will run when something happens) This handler works when
|
|
|
|
you do a **gesture** (like shake, tilt, or drop the micro:bit).
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
```sig
|
|
|
|
input.onGesture(Gesture.Shake,() => {
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
2016-06-09 01:59:20 +02:00
|
|
|
## Example: random number
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2016-06-09 01:59:20 +02:00
|
|
|
This program shows a number from `0` to `9` when you shake the micro:bit.
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
```blocks
|
|
|
|
input.onGesture(Gesture.Shake,() => {
|
|
|
|
let x = Math.random(10)
|
|
|
|
basic.showNumber(x, 100)
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|