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.