2016-03-26 00:47:20 +01:00
|
|
|
# Temperature
|
|
|
|
|
2016-05-25 02:51:10 +02:00
|
|
|
Find the temperature where you are. The temperature is measured in Celsius (metric).
|
2016-11-02 01:44:37 +01:00
|
|
|
The @boardname@ can find the temperature nearby by checking how hot its computer chips are.
|
2016-05-25 02:51:10 +02:00
|
|
|
|
2016-03-26 00:47:20 +01:00
|
|
|
```sig
|
|
|
|
input.temperature();
|
|
|
|
```
|
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
## Returns
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
* a [number](/types/number) that is the temperature in degrees Celsius.
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
## How does it work?
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2016-11-01 18:42:42 +01:00
|
|
|
The @boardname@ checks how hot its CPU (main computer chip) is.
|
2016-11-02 01:44:37 +01:00
|
|
|
Because the @boardname@ does not usually get very hot, the temperature of the CPU
|
2016-05-25 02:51:10 +02:00
|
|
|
is usually close to the temperature of wherever you are.
|
2016-11-02 01:44:37 +01:00
|
|
|
The @boardname@ might warm up a little if you make it work hard, though!
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
Learn more about how the @boardname@ can detect hot or cold in this video:
|
|
|
|
|
|
|
|
https://www.youtube.com/watch?v=_T4N8O9xsMA
|
|
|
|
|
|
|
|
|
|
|
|
## Example: @boardname@ thermometer
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2016-05-25 02:51:10 +02:00
|
|
|
The following example uses `temperature` and `show number` to show the temperature of the room.
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2016-05-25 02:51:10 +02:00
|
|
|
```blocks
|
2016-03-26 00:47:20 +01:00
|
|
|
basic.forever(() => {
|
|
|
|
let temp = input.temperature()
|
|
|
|
basic.showNumber(temp)
|
|
|
|
})
|
|
|
|
```
|
2019-12-02 05:58:26 +01:00
|
|
|
## Example: Fahrenheit thermometer
|
2016-05-25 02:51:10 +02:00
|
|
|
|
|
|
|
This program measures the temperature using Fahrenheit degrees.
|
|
|
|
Fahrenheit is a way of measuring temperature that is commonly used in the United States.
|
|
|
|
To make a Celsius temperature into a Fahrenheit one, multiply the Celsius temperature by
|
2019-12-02 05:58:26 +01:00
|
|
|
``1.8`` and add ``32``.
|
2016-05-25 02:51:10 +02:00
|
|
|
|
|
|
|
```blocks
|
|
|
|
basic.forever(() => {
|
|
|
|
let c = input.temperature()
|
2019-12-02 05:58:26 +01:00
|
|
|
let f = (1.8 * c) + 32
|
2016-05-25 02:51:10 +02:00
|
|
|
basic.showNumber(f)
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
## ~hint
|
2016-05-25 02:51:10 +02:00
|
|
|
|
2016-11-02 01:44:37 +01:00
|
|
|
Try comparing the temperature your @boardname@ shows to a real thermometer in the same place.
|
|
|
|
You might be able to figure out how much to subtract from the number the @boardname@
|
|
|
|
shows to get the real temperature. Then you can change your program so the @boardname@ is a
|
2016-05-25 02:51:10 +02:00
|
|
|
better thermometer.
|
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
## ~
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
## See also
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2016-04-13 17:27:45 +02:00
|
|
|
[compass-heading](/reference/input/compass-heading), [acceleration](/reference/input/acceleration)
|
2016-03-26 00:47:20 +01:00
|
|
|
|