[vc_row][vc_column width=”1/1″][vc_column_text]Pulse Width Modulation (or PWM for short), is a technique for obtaining analog results with digital means. Digital control is used to create a square wave, a signal is switched between on and off. If you repeat this on-off pattern fast enough with an LED for example, the result is as if the signal is a steady voltage between 0 and 5v controlling the brightness of the LED.This experiment is use PWM control LED’s on and off.
By changing the duty ratio to implement the brightness changes of LED.[/vc_column_text][/vc_column][/vc_row][vc_row][vc_column width=”1/1″][vc_tour][vc_tab title=”Wire Diagram” tab_id=”1388111700-1-79″][vc_column_text][/vc_column_text][/vc_tab][vc_tab title=”Instruction” tab_id=”1388111700-2-58″][vc_column_text]This experiment is simple. It uses PWM to dim LED. We will pin 11 of GPIOs of pcDuino to realize the control.
[/vc_column_text][/vc_tab][vc_tab title=”Sample Code” tab_id=”1388125692793-2-7″][vc_column_text]
code instruction
useing loop statement controling LED
*/
int led=10;//connection LED to the pin 10 //
void setup ()
{
pinMode(led,OUTPUT);
}
void loop()
{
for (int a=0; a<=255;a++)
//Increase the brightness of the LED //
{
analogWrite(led,a);
delay(8); //Maintain 8 ms
//Maintain 8 ms
}
for (int a=255; a>=0;a–)
//reduce the brightness of the LED//
{
analogWrite(led,a);
delay(8);
//Maintain 8 ms//
}
delay(800);
//Complete a cycle ,wait 800ms
}[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.