Connect with us

Arduino RGB fading candle... why not.

Discussion in 'Microcontrollers, Programming and IoT' started by cjdelphi, Apr 23, 2012.

Scroll to continue with content
  1. cjdelphi

    cjdelphi

    1,096
    104
    Oct 26, 2011
    I thought i'd share this small video i just made, it's a small changing led RGB candle


    how do you embed a video?
     
  2. cjdelphi

    cjdelphi

    1,096
    104
    Oct 26, 2011
    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.
     
  3. cjdelphi

    cjdelphi

    1,096
    104
    Oct 26, 2011
    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;
    
    }
    
    
     
  4. cjdelphi

    cjdelphi

    1,096
    104
    Oct 26, 2011
    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)
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-