Realistic flame effect with random HELP!!

Hi,

Im obviously very new to this :) and I would really appreciate your expertise. I am currently creating an LED kerosene lantern for interior decoration. To make these LEDs flicker im using the following code:

// LED Fire Effect

int ledPin1 = 6; int ledPin2 = 7; int ledPin3 = 8; int ledPin4 = 9; int ledPin5 = 10; int ledPin6 = 11; int ledPin7 = 12;

void setup() { pinMode(ledPin1, OUTPUT); pinMode(ledPin2, OUTPUT); pinMode(ledPin3, OUTPUT); pinMode(ledPin4, OUTPUT); pinMode(ledPin5, OUTPUT); pinMode(ledPin6, OUTPUT); pinMode(ledPin7, OUTPUT); }

void loop() { analogWrite(ledPin1, random(100)+140); analogWrite(ledPin2, random(100)+140); analogWrite(ledPin3, random(100)+140); analogWrite(ledPin4, random(100)+140); analogWrite(ledPin5, random(100)+140); analogWrite(ledPin6, random(100)+140); analogWrite(ledPin7, random(100)+140); delay(random(110)); }

As ive wired each LED to a different pin each led flickers randomly from eachother therefor cancelling out the overall effect. Is there a way that I can flicker randomly but together so they all dimm and become brighter at the same time in sync?

Thankyou so much for your help :D

try this:
void loop() {
int Rand=random(100)+140;
for(int lp= ledPin1;lp<= ledPin7;lp++)
analogWrite(lp, Rand);
delay(random(110));
}

Edit: bug removed

It says error compiling

It says error compiling

I bet it says more than that (hint)

core.a(main.cpp.o): In function main': /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/main.cpp:7: undefined reference tosetup'

Yes, but I can't see your code (hint)

void loop() {
int Rand=random(100)+140;
for(int lp= 6;lp<= 12;lp++)
analogWrite(lp, Rand);
delay(random(110));
}

It looks like you are trying to run the code fragment I gave you as is. You'll need to replace your loop function in your original sketch with the one I gave you instead - it needs all the other stuff you had defined.

Thanks, that was really stupid of me

Hi.

I tried that code but the leds are still random from eachother, does any one know if it is possible to have the exact same signal come through all the pins?

Write the same value to all pins?

Try this:
void loop() {
int Rand=random(100)+140;
for(int lp= ledPin1;lp<= ledPin7;lp++)
analogWrite(lp, Rand);

} // end FOR
delay(random(110));

}// end LOOP

The random delay inside the for loop caused the asynchronous lighting.

Thanks :D

When is use the above code i get the error message

void loop() {
int Rand=random(100)+140;
for(int lp= ledPin1;lp<= ledPin7;lp++)
analogWrite(lp, Rand);

} // end FOR
delay(random(110));

}// end LOOP

Flame_effect:27: error: expected constructor, destructor, or type conversion before ‘(’ token
Flame_effect:29: error: expected declaration before ‘}’ token

Sorry - wrote it on my iphone.

I had copied and pasted the PREVIOUS code which was missing an opening brace on the for loop, then added an extraneous closing brace.
Here is a complete sketch that should work.

int ledPin1 = 6;
int ledPin2 = 7;
int ledPin3 = 8;
int ledPin4 = 9;
int ledPin5 = 10;
int ledPin6 = 11;
int ledPin7 = 12;

void setup()
{
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin6, OUTPUT);
pinMode(ledPin7, OUTPUT);
}
void loop() {
int Rand=random(100)+140;
for(int lp= ledPin1;lp<= ledPin7;lp++){
   analogWrite(lp, Rand);

} // end FOR
delay(random(110));

}// end LOOP

–EDIT added code block

Thankyou sooo much 4 ur help. IT WORKS!!!! :D