Could a bike-light reminder cope with a cloudy Irish evening without flickering?
You're getting your bike ready outside the GAA club. An LED reminds you to turn on your bike lights when it gets dark. But as clouds pass overhead, the reminder keeps blinking. How could it decide when to stay on without anyone pressing a button?
You already know how to read an enable switch and a light sensor together. The switch gives you a digital value. Measure the analogue signal and use the sensor's calibration to convert the reading to lux. Store both input values with the time, then use them to control the reminder LED.
With the switch enabled, take a reading every tenth of a second without waiting for a button press. Turn the LED on below forty lux and off otherwise. Watch the readings cross forty lux three times. Each crossing flips the output, so the reminder flickers.
You still have one threshold, and the switch is enabled. The LED is on at thirty-nine lux because that's below forty. The rule says off otherwise. The next reading is exactly forty lux. Pick what the program does next.
Start off. Each tick, read the switch and sensor, convert to lux and log both inputs with the time. If disabled, set off. Otherwise, set on at thirty-five lux or below and off at forty-five or above. Keep the state between thresholds, then write it to the LED. This is hysteresis.
Start enabled and off at fifty lux. Light drops at one point zero two seconds. At one point one zero, the controller reads thirty-four lux and the LED turns on. Subtract the times. At forty it stays on, at forty-six it turns off, and disabling the switch keeps it off in darkness.
Start enabled with the LED off. Set the on rule to thirty lux or below and the off rule to fifty lux or above. The next three readings are twenty-eight, forty-two, then fifty lux. Pick the LED states after those three updates.
The switch is enabled, the LED was on, and the next reading is forty lux. Reset the state to off every tick and neither threshold will change it, so the LED goes off. Initialise only once before the loop and the same reading keeps the LED on.
Start enabled and off. Your team wants no alerts during the fluctuation: unwanted switch-ons drop from two to zero. With the same step timing, both turn on after zero point zero eight seconds, within the limit. In your own log, record your threshold change, both counts and both delays.
If the question asks you to describe how you tested the system, give the inputs you applied and the LED states you observed. To evaluate it, compare those results with your team's requirements. Before claiming it always meets the timing limit, repeat the light change at different points between sensor readings.