Sunday, 8 May 2016

3: Dimming (the Hard Way)

Yikes! Some of those 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.)

Background Information

Remember that the Arduino 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.

Code Components

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.

Do This

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 9 and 10. Can you spot a difference between the two? One LED should look dimmer in comparison to the other. That’s because one 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)?

Further Explorations

  • How long can you make the delays before you start noticing a blink?
  • What happens if you add something else to the loop section, like your animation from experiment two?

No comments:

Post a Comment