pxt-calliope/docs/lessons/temperature/activity.md

41 lines
1.1 KiB
Markdown
Raw Permalink Normal View History

2016-03-26 00:47:20 +01:00
# temperature activity
2016-11-02 01:44:37 +01:00
Measure the temperature on the @boardname@
2016-03-26 00:47:20 +01:00
2016-11-02 01:44:37 +01:00
Welcome! This activity will teach how to measure the temperature on the @boardname@. Let's get started!
2016-03-26 00:47:20 +01:00
2016-11-02 01:44:37 +01:00
We want to display the temperature on shake. In order to do so, we need to register the event `on shake` that will execute whenever the user shakes the @boardname@; in the web browser, click the button labelled "SHAKE" under the simulator to generate a shake event
2016-03-26 00:47:20 +01:00
```blocks
input.onGesture(Gesture.Shake, () => {
})
```
Let's measure the temperature and then store in it a variable `temp`. The temperature is measured in **Celsius**, so a value of `29` is equivalent to 29 degrees Celsius.
```blocks
input.onGesture(Gesture.Shake, () => {
let temp = input.temperature()
})
```
Show the value of `temp` on the screen.
```blocks
input.onGesture(Gesture.Shake, () => {
let temp = input.temperature()
basic.showNumber(temp)
})
```
* click run to see if the code works as expected.
### ~avatar avatar
2016-04-13 17:27:45 +02:00
Excellent, you're ready to continue with the [challenges](/lessons/temperature/challenges)!
2016-03-26 00:47:20 +01:00
### ~