Digital Sandbox Experiment Guide
3: Dimming (the Hard Way)
Yikes! Those white LEDs are blindingly bright! Is there any way to dim them? (Unless one of your hobbies is staring into the sun, we recommend putting a piece of paper over the LEDs in this experiment...or wear sunglasses.)
Remember that the Digital Sandbox is fast. It can flick an LED on and off millions of times per second. What if we blinked the LED super fast, but also make it so the length of time the LED is off is more than the length of time it's on? This is called pulse-width modulation (PWM), a tool with a variety of applications, including dimming the LEDs.
In this experiment we'll explore PWM the hard way, by coding it in manually.
We'll use a similar set of blocks:
Take note of how long each delay is, and which pins are on/off in each group.
Stack the two group of threes on top of each other, in the loop section, and Upload.
After uploading, take a close look at the LEDs connected to pins 5 and 6. Can you spot a difference between the two? The D6 LED should look dimmer in comparison to D5. That's because D6 is set to be low 90% of the time, and on only 10%. It's blinking on and off so fast that you can't notice. But what the blinking is creating is a dimming effect.
What happens if you swap the two Delay Millisecond blocks? What if you change the values in each of the delay blocks (try to keep the sum of the delay times to around 10ms)?
- How long can you make the delays before you start noticing a blink?
- Try comparing both LEDs to a fully-on LED. Add a Set Digital Pin block to the setup, and have it turn the D4 LED HIGH. Can you tell a difference between D4, D5, and D6?
- What happens if you add something else to the loop section, like your animation from experiment two?