5,710
edits
Changes
→LED Dimming
*File->Sketchbook->Examples->Analog->Fading
The crux of this sketch is the <code>analogWrite() </code> function.
<youtube v="62gWVWCyw_w" loop="true"/>
* Get this working. Then...
* Q: Drive this dimming example with the light sensor from before.
** use <code>analogRead()</code> to get the value from the sensor, like you did before, then use <code>analogWrite()</code> to output the value to the LED. NOTE: <code>analogRead()</code> will return values from 0-1023, and <code>analogWrite()</code> writes values from 0 to 255, so you will need to divide your read value by 4 to get the output value. Or you could use <code>map()</code>
* Q: Does yours turn on when it is light, or does it turn off? Switch this to give it the opposite behavior, in either hardware or software. You could do either!