Monday, 21 March 2016

LED project. An Arduino fireplace.

I wanted to make a project that made the light coming off some LED's look like the light from a fireplace. it consists of some yellow and some red leds these randomly turn off and on very quickly giving the appearance of a dancing flame. there is some RBG led's that slowly change between yellow and red then back again giving the appearance of wing on hot coals.



Reflection


*Code follows*

//rgb colour fade
#define GREEN 3
#define BLUE 5
#define RED 6
#define delayTime 1000

//red & yellow LED Fire Effect
int ledPin1 = 10;
int ledPin2 = 9;
int ledPin3 = 11;
int ledPin4 = 8;
int ledPin5 = 7;
//rgb colour fade
int redVal;
int blueVal;
int greenVal = 0;
int pin1Milli;
int pin2Milli;
int pin3Milli;
int pin4Milli;
int pin5Milli;
bool fadeDirection = true;

void setup()
{
//red & yellow LED Fire Effect
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
//rgb colour fade
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
pinMode(RED, OUTPUT);
digitalWrite(GREEN, HIGH);
digitalWrite(BLUE, HIGH);
digitalWrite(RED, HIGH);

pin1Milli = random(120)+135;
pin2Milli = random(120)+135;
pin3Milli =random(120)+135;
pin4Milli =random(120)+135;
pin5Milli =random(120)+135;

Serial.begin(9600);


}

void loop() {
//red & yellow LED Fire Effect
  if(millis() >= pin1Milli)
  {
    analogWrite(ledPin1, pin1Milli);
    pin1Milli = random(120)+135;
  }
    if(millis() >= pin2Milli)
  {
    analogWrite(ledPin2, pin2Milli);
    pin2Milli = random(120)+135;
  }
    if(millis() >= pin3Milli)
  {
    analogWrite(ledPin3, pin1Milli);
    pin3Milli = random(120)+135;
  }
    if(millis() >= pin4Milli)
  {
    analogWrite(ledPin4, pin1Milli);
    pin4Milli = random(120)+135;
  }
    if(millis() >= pin5Milli)
  {
    analogWrite(ledPin5, pin4Milli);
    pin5Milli = random(120)+135;
  }

//rgb colour fade
 redVal = 255;
 blueVal = 0;
 if(millis() >= delayTime && fadeDirection == true)
 {
  greenVal += 1;
    analogWrite( GREEN, greenVal );
    analogWrite( RED, redVal );
    Serial.println(greenVal);
     analogWrite( BLUE, 0 );
    if(greenVal == 30)
    {
      fadeDirection = false;
    }
    
 }
 else if(millis() >= delayTime && fadeDirection == false )
 {
    greenVal -= 1;
    analogWrite( GREEN, greenVal );
    analogWrite( RED, redVal );
    analogWrite( BLUE, 0 );
    Serial.println(greenVal);
    if(greenVal == 0)
    {
      fadeDirection = true;
    }
 }
}


my original thought was to make a mirror that looked deeper than it was by bouncing light off two mirrors but the LED strip lights I ordered haven't shown up yet.
I got the idea from the old heaters that looked like a fireplace.