1/07/2014

(Arduino study) LED brightness change by pwm ( analogWrite function )

A analogWrite function generate PWM pules easy.
It can use to a motor control.




very very simple source code.
---
int ledPin = 10;

void setup(){
}

void loop(){
  //increase brightness step by +5
  for(int fadeValue = 0; fadeValue < 256; fadeValue +=5)
  {
    analogWrite(ledPin, fadeValue);
    delay(30); //wait 0.01sec
  }
  
  //decrease brightness step by -5
  for(int fadeValue=255; fadeValue >=0; fadeValue-=5)
  {
    analogWrite(ledPin, fadeValue);
    delay(30); //wait 0.01sec
  }
}
...

No comments:

Post a Comment