I’m working on a project in MIT App Inventor where I use the light sensor to detect flashes of light. Instead of having the sensor running constantly, I want to store multiple flashes and activate the phone’s flash when I detect four "1s" (four flashes).
My idea is to:
Detect a flash and store a value of 1.
Keep a count of detected flashes.
Activate the phone's flash once four flashes (four "1s") have been detected.
How can I implement this logic efficiently in MIT App Inventor? Is there a way to control when the sensor reads values to avoid continuous processing?
Any help or suggestions would be greatly appreciated!
Detecting a flash requires you to keep a history of lux readings by time.
The Clock1.SystemTime block will return milliseconds from 1970, which (if adjusted to app start time) can give you an x axis for timestamped lux readings in a two column table (timestamp, reading).
You only need keep the last minute or so of readings, since the count should reset after you reach 4 flashes.
A flash might be detected as a sequence of three readings in the table, where
lux(n-1) < lux(n) and
lux(n+1) < lux(n)
( a local peak in the lux values.)
If you clear the table when you reach 4 peaks, you need not bother keeping the timestamp column.