Both pushbutton function is similar to the volume-up and volume- down. Which one to increase the volume (brightness), while the other is to lower the volume (brightness). Yes, at least you know what I mean.
Controlling Brightness LED |
There are at least two ways to increase or decrease the brightness of LED:
- Change the current into the LED, this method can be applied by changing the resistor value
- switch off the LED with sooner or later. Well, when we switch off the LED quickly, the human eye can not figure it out. Captured by the eye is the lightness or dimness only. If we switch off led quickly, then it will look bright LED, but if we toggling the LED at a slower, then the LED will appear dimmer.
In digital electronics, the second concept known as PWM (Pulse Width Modulation). What PWM?
Most foot / Arduino pin PWM support, leg support PWM marked by a tilde sign (~) in front of the pin number, such as 3, 5, 6, and so on. The frequency used in the Arduino's PWM is 500Hz (500 cycles in 1 second). So, Arduino can switch off the LED 500 times in one second.
To use PWM, we can use the function analogWrite (). The value can be put on the functionality that is between 0 and 255. A value of 0 means the pulse is given for each cycle is always 0 volts, while the value of 255 means that a given pulse is always worth 5 volts.
PWM pulse cycle |
If we give the value of 127 (we assume half of 0 to 255, or 50% of 255), then the half cycle will be worth 5 volts, and half again the cycle will be 0 volts. Whereas if if it gives 25% of 255 (1/4 * 255 or 64), then 1/4 of the cycle will be worth 5 volts, and the remaining 3/4 will be 0 volts, and this will happen 500 times in one second. For visualization of the PWM cycle, you can see the picture above.
0 Response to "Controlling Brightness LED"
Post a Comment