Add light sensor event that only fires when valid reading is available. #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New event
MICROBIT_DISPLAY_EVT_LIGHT_SENSE_READY
is introduced to resolve two issues.This allows for four different behaviours depending on how you interact with the light sensor as shown in the code sample below.
false
toreadLightLevel
gives the same behaviour as before, simply returning the values (including invalid ones) every time a reading is taken.true
to 'readLightLevel' causes an error value of-1
to be returned for the first few readings, and stale but valid readings to be returned whenever invalid results are produced.readLightLevel
is only called when a valid reading is available.true
toreadLightLevel
when using the new event means that even if a bad result is produced between the event firing and the call toreadLightLevel
, a valid reading will still be returned (either the reading taken when the event was fired, or a more recent valid reading).