Flickering LEDs – proof of concept

My first project is to light a string of papier-m??ch?? hot air balloons. I was just going to light them with some LEDs, but then I heard about the Arduino and wanted to make something more exciting. I got a starter kit from adafruit.com and got to work.

This is the first proof of concept of making the LEDs flicker. Later I???ll add a light sensor to start a sleep timer that will turn the balloons off after a half hour.

Here???s the sketch that runs what you see above:

/** randomly flickering LEDs*/int ledPin[] = {5, 6, 9, 10, 11};              // pwm pins onlyint ledState[5];                 // last state of each ledlong randNumber;void setup() {for (int i=0; i<5; i++){       // set each led pin as an output  pinMode(ledPin[i], OUTPUT);   }randomSeed(analogRead(0));     // seed the rnd generator with noise from unused pinfor (int i=0; i<5; i++){       // init each led with a random value  ledState[i] = random(20, 201);}}void loop(){for (int i=0; i<5; i++){                   // for each led:  analogWrite(ledPin[i], ledState[i]);     // set the pwm value of that pin determined previously  randNumber = random(-35, 41);            // generate new random number and add that to the current value  ledState[i] += randNumber;               // that range can be tweaked to change the intensity of the flickering  if (ledState[i] > 200) {                 // now clamp the limits of the pwm values so it remains within    ledState[i] = 200;                     // a pleasing range as well as the pwm range  }  if (ledState[i] < 10) {    ledState[i] = 10;  }}delay(100);    // the delay between changes}
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s