I created an LED that can use switch to turn ON/OFF and use the photo resistor to change its lightness, as demonstrated in the video. The lightness of the LED does not change so drastically, maybe because of the photo resistor is having trouble accurately detect the light, or I maybe because I mapped the lightness not so well. It's strange no matter how I change the mapping function, the lightness of LED does not change so much, though.
I used the tutorials on our IoT website, the switch one and the photo resistor one for reference. These codes seems to work and I figured it out how to combine them together.
It takes a long time for me to incorporate the switch in and change the mapping of lightness of the resistor. It turned out to be that I didn't link the switch to the GND.
Finally the switch and the photo resistor is working.
I find it hard to map the LED lightness. I tried to detect the range of photo resistor using photoCellReading, finding it to be among 500 to 1500. However, I tried to map the LED lightness to this range, it still doesn't work so well. Maybe because I'm in the library and the ambient lightness is not so ideal. I also found we should be careful with the resistor. Incorporating the right one in the right place takes time.
You can upload files of up to 20MB using this form.