Pulse Width Modification is a power controlling technique where we get analog results from digital means. In this we modify the on-off pattern of a digital clock to vary the analog values.
As we mix the colour paints on the palette, we can mix the colours of LEDs using PWM. This can be done using the command analogWrite.
analogWrite() takes the value from 0-255.
255=100% duty cycle; 127=50% duty cycle;
int led=11; int brightness=255; int fade=5;
void setup()
{
pinMode(led, OUTPUT);
}
void loop()
{
analogWrite(led, brightness);
brightness=brightness-fade;
if(brightness==255||brightness==0) //reversing effect
!fade;
delay(100);
}
As we mix the colour paints on the palette, we can mix the colours of LEDs using PWM. This can be done using the command analogWrite.
analogWrite() takes the value from 0-255.
255=100% duty cycle; 127=50% duty cycle;
Code:
int led=11; int brightness=255; int fade=5;
void setup()
{
pinMode(led, OUTPUT);
}
void loop()
{
analogWrite(led, brightness);
brightness=brightness-fade;
if(brightness==255||brightness==0) //reversing effect
!fade;
delay(100);
}
No comments:
Post a Comment