pxt-calliope/docs/reference/input/on-gesture.md

27 lines
674 B
Markdown
Raw Normal View History

2016-03-26 00:47:20 +01:00
# On Gesture
Start an [event handler](/reference/event-handler) (part of the
program that will run when something happens) This handler works when
2016-07-16 01:43:26 +02:00
you do a **gesture** (like shaking the micro:bit).
2016-03-26 00:47:20 +01:00
```sig
input.onGesture(Gesture.Shake,() => {
})
```
2016-07-16 01:43:26 +02:00
### Parameters
* ``gesture`` means the way you hold or move the micro:bit. This can be `shake`, `logo up`, `logo down`, `screen up`, `screen down`, `tilt left`, `tilt right`, `free fall`, `3g`, or `6g`.
### Example: random number
2016-03-26 00:47:20 +01: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)
})
```