Light sensor

Events

The on light condition changed event allows to run code when the light goes dark or bright. For example, you can use the on light bright event to detect a sudden flash of light.

Live data

The light level returns the current light intensity reading between 0 (no light) and 255 (max light).

Example

In this example, we add a on light bright event to run the sparkle animation when a flash is detected. Using a forever loop, we use the light intensity to control the pitch of the tones played on the speaker.

This guide was first published on Jun 07, 2017. It was last updated on Jun 07, 2017. This page (Light sensor) was last updated on Sep 18, 2019.