Exercise 3
Task 1
Modify your blinky program such that it blinks faster when the LDR is covered, and slower when it is exposed to light.
Hint
Check whether the sensorValue is greater than say, 512 (approx. half of the maximum, which is 1023) using an if condition.
The threshold can be set to 512 (approx. half of the maximum, which is 1023) if you chose Option 2 in the Connecting LDR section.
If you chose Option 1, you might need to find the threshold experimentally (though 512 should work in most cases). Use the program in the analogRead() Serial Example section to print the reading 1) when the LDR is fully exposed to light and 2) when the LDR is fully covered. The mean of the two can be used as the threshold.
Task 2
Modify your program such that
When the switch is off
The message OFF is printed repeatedly via Serial once every second, and the LED remains fully turned off.
When the switch is on
The LED will gradually turn on and off repeatedly at a fast rate when LDR is covered, and at a slower rate when it is exposed to light.
The message ON is printed repeatedly via Serial every time the LED brightness is maximum (i.e., one message every on-off cycle of the LED).