/* Fireplace Turns a series of LED arrays on and off at random intervals. PWM is used to vary the brightness of some arrays at random intervals. There are not enough PWM outputs for all the arrays, so some are simply switched on and off */ const int pwm1 = 3; // define our output pins const int pwm2 = 5; const int pwm3 = 6; const int pwm4 = 9; const int pwm5 = 10; const int pwm6 = 11; const int io2 = 2; // these pins do not provide PWM const int io4 = 4; const int io7 = 7; // the setup function runs once when you press reset or power the board void setup() { // initialize the PWM pins as outputs. digitalWrite(pwm1, LOW); // turn the LED off by making the voltage LOW pinMode(pwm1, OUTPUT); digitalWrite(pwm2, LOW); // turn the LED off by making the voltage LOW pinMode(pwm2, OUTPUT); digitalWrite(pwm3, LOW); // turn the LED off by making the voltage LOW pinMode(pwm3, OUTPUT); digitalWrite(pwm4, LOW); // turn the LED off by making the voltage LOW pinMode(pwm4, OUTPUT); digitalWrite(pwm5, LOW); // turn the LED off by making the voltage LOW pinMode(pwm5, OUTPUT); digitalWrite(pwm6, LOW); // turn the LED off by making the voltage LOW pinMode(pwm6, OUTPUT); digitalWrite(io2, LOW); // turn the LED off by making the voltage LOW pinMode(io2, OUTPUT); digitalWrite(io4, LOW); // turn the LED off by making the voltage LOW pinMode(io4, OUTPUT); digitalWrite(io7, LOW); // turn the LED off by making the voltage LOW pinMode(io7, OUTPUT); // we will be sending random durations and random intensity levels to // the various LED boards to flicker the 'flames' randomSeed(analogRead(0)); // generate a random seed } // the loop function runs over and over again forever void loop() { int rnd; // set random intensity levels for the LED boards // controlled by PWM outputs rnd = random(1,256); analogWrite(pwm1,rnd); rnd = random(1,256); analogWrite(pwm2,rnd); rnd = random(1,256); analogWrite(pwm3,rnd); rnd = random(1,256); analogWrite(pwm4,rnd); rnd = random(1,256); analogWrite(pwm5,rnd); rnd = random(1,256); analogWrite(pwm6,rnd); // randomly turn on or off the LED boards controlled // by standard I/O pins if (random(0,2)){digitalWrite(io2, HIGH);} else {digitalWrite(io2, LOW);} if (random(0,2)){digitalWrite(io4, HIGH);} else {digitalWrite(io4, LOW);} if (random(0,2)){digitalWrite(io7, HIGH);} else {digitalWrite(io7, LOW);} // pause for a random interval to display these light levels // in the fireplace delay(random(200,2000)); }