Thursday, October 16, 2014

//A simple code that brightens and dims an Led.
int brightness=0;
int fadeamount=5;

void setup(){
  pinMode(3, OUTPUT);
}

void loop(){
  analogWrite(3, brightness);
  brightness=brightness+fadeamount;
 
  if(brightness==0||brightness==255){
    fadeamount=-fadeamount;
  }

  delay(30);
}

//Unlike the other dimming code, you cannot control
//the individual speed of dimming and increasing of brightness
//you have 1 speed for both, which is the delay

No comments:

Post a Comment