Maker Pro
Maker Pro

Arduino RGB fading candle... why not.

I guess the answer is, you can't lol :) - not too bad for my first attempt doing anything like that, all my own code from start to finish too lol! enjoy.
 
Code:
int ledPin1 = 9;  
int ledPin2 = 10;
int ledPin3 = 11;// LED connected to digital pin 9
int val = 0;         // variable to store the read value
boolean firstcycle = false;

void setup()
{
  pinMode(ledPin1, OUTPUT);   // sets the pin as output
  pinMode(ledPin2, OUTPUT);   // sets the pin as output
  pinMode(ledPin3, OUTPUT);   // sets the pin as output
  
}

void loop()
{
  int n;
  int n2;
  int n3;
   delay(3000);
   digitalWrite(ledPin1,LOW);
   digitalWrite(ledPin2,LOW);
   digitalWrite(ledPin3,LOW);   
//  val = analogRead(analogPin);   // read the input pin
  n2=255;
  if (firstcycle==false) {
  for (n=0; n<255; n++)
  { 
     analogWrite(ledPin1, n);  // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
     delay(15);
     n2--;
    }
  }


  n2=0;

  for (n=255; n>0;)
  { 
     analogWrite(ledPin1, n);  // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
     analogWrite(ledPin2, n2);  // analogRead values go from 0 to 1023, analogWrite values from 0 to 255     
     delay(15);
     n--;
     n2++;
  }


  n2=255;
  for (n=0; n<255;)
  { 
     
     analogWrite(ledPin2, n2);  // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
     analogWrite(ledPin3, n); 
     delay(15);
     n++;
     n2--;
  }



 for (n=255; n>0;)
  { 
     analogWrite(ledPin3, n);  // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
     analogWrite(ledPin1, n2);  // analogRead values go from 0 to 1023, analogWrite values from 0 to 255     
     delay(15);
     n--;
     n2++;
  }
  
  firstcycle=true;

}
 
ok i lie, the lines with comments are pasted :D - sorry to the guys who wrote those original functions i mean returns (stupid...) :D i'm from a pascal background (Delphi)
 
Top