2016-03-26 00:47:20 +01:00
|
|
|
# Light Level
|
|
|
|
|
2016-05-23 23:46:11 +02:00
|
|
|
Find the light level (how bright or dark it is) where you are.
|
2016-05-23 22:41:01 +02:00
|
|
|
The light level ``0`` means darkness and ``255`` means bright light.
|
2016-11-01 18:42:42 +01:00
|
|
|
The @boardname@ measures the light around it by using some of the
|
2016-05-23 22:41:01 +02:00
|
|
|
LEDs on the [LED screen](/device/screen).
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2016-05-23 22:41:01 +02:00
|
|
|
The first time you use it, this function will say ``0``.
|
|
|
|
After that, it will say the real light level.
|
|
|
|
This is because the light sensor (the part that can find the light level)
|
|
|
|
has to be turned on first.
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
```sig
|
|
|
|
input.lightLevel();
|
|
|
|
```
|
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
Learn more about how light level is detected in this light sensor video:
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
https://www.youtube.com/watch?v=TKhCr-dQMBY.
|
2016-05-23 22:41:01 +02:00
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
## Returns
|
|
|
|
|
|
|
|
* a [Number](/types/number) that means a light level from ``0`` (dark) to ``255`` (bright).
|
|
|
|
|
|
|
|
## Example: show light level
|
2016-05-23 22:41:01 +02:00
|
|
|
|
|
|
|
When you press button `B` on the microbit, this
|
|
|
|
program shows the light level
|
|
|
|
on the [LED screen](/device/screen).
|
|
|
|
|
|
|
|
```blocks
|
2022-04-26 19:28:42 +02:00
|
|
|
input.onButtonEvent(Button.B, ButtonEvent.Click, () => {
|
2016-05-23 22:41:01 +02:00
|
|
|
let level = input.lightLevel()
|
|
|
|
basic.showNumber(level)
|
|
|
|
})
|
|
|
|
```
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
## Example: chart light level
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2016-11-02 01:44:37 +01:00
|
|
|
This program shows the light level with a [bar chart](/reference/led/plot-bar-graph) on the @boardname@ screen.
|
|
|
|
If you carry the @boardname@ around to different places with different light levels,
|
2016-05-23 22:41:01 +02:00
|
|
|
the bar chart will change.
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
```blocks
|
|
|
|
basic.forever(() => {
|
|
|
|
led.plotBarGraph(input.lightLevel(), 255)
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
## See also
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2016-04-18 18:47:34 +02:00
|
|
|
[acceleration](/reference/input/acceleration), [compass-heading](/reference/input/compass-heading)
|
2016-03-26 00:47:20 +01:00
|
|
|
|