“Lesson 5--Microduino “LED Brightness and Potentiometer PWM””的版本间的差异
Jasonsheng(讨论 | 贡献) (→Program) |
Jasonsheng(讨论 | 贡献) |
||
第5行: | 第5行: | ||
==Objective== | ==Objective== | ||
Last lesson we use the button to generate PWM to control the LED, this lesson we will use precision potentiometer to control the LED. | Last lesson we use the button to generate PWM to control the LED, this lesson we will use precision potentiometer to control the LED. | ||
− | The | + | The difference between them is that the button use the digital voltage signal (0 and 1) to control which only has two states. |
− | When the signal changed,LED increases brightness by 5 units (0 ~ 255). | + | When the signal changed, LED increases brightness by 5 units (0 ~ 255). |
− | Potentiometer | + | Potentiometer uses the analog voltage to generate PWM which is a linear change of state, so the LED's brightnee can be changed coherently and softly. |
Conversely,if use the button, you need consider the button shaking. | Conversely,if use the button, you need consider the button shaking. | ||
第26行: | 第26行: | ||
the measurement accuracy of the voltage variation is relatively high. | the measurement accuracy of the voltage variation is relatively high. | ||
Potentiometer had better choose winding precision linear potentiometer, | Potentiometer had better choose winding precision linear potentiometer, | ||
− | because some cheap nonlinear potentiometer on the market doesn't have a good electrical | + | because some cheap nonlinear potentiometer on the market doesn't have a good electrical characteristic. |
− | + | Numerical drift is big which easy to cause the led flashing, Resistance is nonlinear variation, so | |
the brightness change is not obvious, easy to produce the sense of hierarchy just like the button dimmer experiments, | the brightness change is not obvious, easy to produce the sense of hierarchy just like the button dimmer experiments, | ||
impact the test results. | impact the test results. | ||
第56行: | 第56行: | ||
==Result== | ==Result== | ||
− | With the rotation of the potentiometer, LED brightness changes softly. | + | With the rotation of the potentiometer, LED's brightness changes softly. |
==Video== | ==Video== | ||
|} | |} |
2014年8月19日 (二) 13:37的版本
Language | English |
---|
ObjectiveLast lesson we use the button to generate PWM to control the LED, this lesson we will use precision potentiometer to control the LED. The difference between them is that the button use the digital voltage signal (0 and 1) to control which only has two states. When the signal changed, LED increases brightness by 5 units (0 ~ 255). Potentiometer uses the analog voltage to generate PWM which is a linear change of state, so the LED's brightnee can be changed coherently and softly. Conversely,if use the button, you need consider the button shaking. Equipment
Experimental schematicConnection method, LED connects to the PWM output pin, and potentiometer connects to analog port A0 ~ A5. Analog interface can measure 0-5V voltage, and the corresponding return value is 0-1024, the measurement accuracy of the voltage variation is relatively high. Potentiometer had better choose winding precision linear potentiometer, because some cheap nonlinear potentiometer on the market doesn't have a good electrical characteristic. Numerical drift is big which easy to cause the led flashing, Resistance is nonlinear variation, so the brightness change is not obvious, easy to produce the sense of hierarchy just like the button dimmer experiments, impact the test results. Programvoid setup()
{
pinMode(3,OUTPUT); //Choose the PWM output Port
}
void loop()
{
int val= analogRead(A0); //Read the analog port A0's value(voltage range is0-5V,corresponding value is 0-1204)
val = map(val, 0, 1023, 0, 255);
//Mapping the analog value(0~1024)to(0~255),the Max PWM value is 255。
analogWrite(3, val);
//analogWrite(11,val/4); //The max PWM value is 255,so the analog value is divided by 4.
}
map() function
ResultWith the rotation of the potentiometer, LED's brightness changes softly. Video |