| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Flicker Sketch

Page history last edited by PBworks 16 years, 9 months ago

 

Flicker Sketch

This sketch uses an array of numbers to set the brightness of an LED with the analogWrite command. This sketch also introduces the random command to generate a random delay between each brightness level.

 

NOTE: This only works on those pins marked PWM (11, 10, 9, 6, 5, 3).

 

/*  Flicker Sketch

    Uses an array and a random delay

    to create a flicker effect.

*/

 

int ledPin = 9;

int randNumber;

byte flicker[] = {180, 30, 255, 200, 10, 90, 40, 150, 20, 60};

 

void setup()

{

  pinMode(ledPin, OUTPUT);

  randomSeed(millis());              // sets millis() as seed

}

 

void loop()

{

  for(int i=0; i<10; i++)            // loop equal to number

  {                                  // of values in array

    analogWrite(ledPin, flicker[i]); // write value of array

    randNumber = random(50, 250);    // random number from 50-250

    delay(randNumber);               // random delay

  }

}

 

Comments (0)

You don't have permission to comment on this page.