pxt-calliope/docs/reference/input/light-level.md
Juri Wolf a93febb5b7
Map and clean deprecated functions (#175)
* add image and deprecated arrow functions

* update locales

* map basic.showArrow

* map arrow blocks

* map & remove arrow images

* remove arrow blocks

* update locales

* remove & patch:
rgbw -> rgb
button/pin pressed -> button/pin event
loudness -> soundLevel

* update ts mappings for arrows

* add wip ts patch rules

* update .blocks files

* use Click instead of Down as default in Documentation and tests

* patch test.blocks

* fix lowercase name tag

* update test.blocks

* update blocks test files

* update blocks test files

* format block files

* pass blocks file tests

* fix ts mapping

* fix color.defl value

closes https://github.com/microsoft/pxt-calliope/issues/136

* fix ts mappings

- add optional spacing at the end of rgbw()
- map up to v4.0.19

* add suggested changes

* replace innerText by textContent

Co-authored-by: JW <gitkraken@juriwolf.de>
Co-authored-by: Juri <info@juriwolf.de>
2022-04-26 10:28:42 -07:00

54 lines
1.4 KiB
Markdown

# Light Level
Find the light level (how bright or dark it is) where you are.
The light level ``0`` means darkness and ``255`` means bright light.
The @boardname@ measures the light around it by using some of the
LEDs on the [LED screen](/device/screen).
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.
```sig
input.lightLevel();
```
Learn more about how light level is detected in this light sensor video:
https://www.youtube.com/watch?v=TKhCr-dQMBY.
## Returns
* a [Number](/types/number) that means a light level from ``0`` (dark) to ``255`` (bright).
## Example: show light level
When you press button `B` on the microbit, this
program shows the light level
on the [LED screen](/device/screen).
```blocks
input.onButtonEvent(Button.B, ButtonEvent.Click, () => {
let level = input.lightLevel()
basic.showNumber(level)
})
```
## Example: chart light level
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,
the bar chart will change.
```blocks
basic.forever(() => {
led.plotBarGraph(input.lightLevel(), 255)
})
```
## See also
[acceleration](/reference/input/acceleration), [compass-heading](/reference/input/compass-heading)