Friday, September 9, 2011

Fading Leds With Arduino!



This is just the source code, for now. I will write a tutorial later.

Source Code-


/*This is my attemp to copy http://www.youtube.com/watch?v=xI-sODvkuTM&feature=watch_response_rev
 or an illusion of the leds fading smoothly to the next one.
 */


int thr=0;   // represents brightness for pin,
int fiv=50;  // each integer's name is the firs three letters of the pin
int six=100; // it represents of the pin it represents this is just to keep
int nin=150; // track it represents
int ten=205;
int ele=255;




int c1=5;  //c represents change, each pin gets its own change
int c2=5;  // so it wont interfere with any other pin
int c3=5;
int c4=5;
int c5=5;
int c6=5;


void setup(){
  pinMode(3,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(11,OUTPUT);
}
void loop(){
  analogWrite(3,thr);
  thr=thr+c1;
  analogWrite(5,fiv);
  fiv=fiv-c2;
  analogWrite(6,six);
  six=six-c3;
  analogWrite(9,nin);
  nin=nin-c4;
  analogWrite(10,ten);
  ten=ten-c5;
  analogWrite(11,ele);
  ele=ele-c6;
  
  
  if(thr==0 || thr==255){
    c1=-c1;
  }
  if(fiv==0 || fiv==255){
    c2=-c2;
  }
  if(six==0 || six==255){
    c3=-c3;
  }
  if(nin==0 || nin==255){
    c4=-c4;
  }
  if(ten==0 || ten==255){
    c5=-c5;
  }
  if(ele==0 || ele==255){
    c6=-c6;
  }
  delay(10);
}


No comments:

Post a Comment