/*
Whacky Fade
Utilizo este código para simular un mal funcionamiento de un viejo letrero luminoso.
El efecto aleatorio imita un mal funcionamiento debido a corto circuitos.
I use this code to simulate a malfunction of an old illuminated sign.
The random effect mimics a malfunction due to short circuits.
*/
int led = 9; // the PWM pin the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
long randomNumber;
void setup() {
// declare pin 9 to be an output:
pinMode(led, OUTPUT);
}
void loop() {
// set the brightness of pin 9:
analogWrite(led, brightness);
// change the brightness for next time through the loop on random amounts:
randomNumber = random(1,50);
brightness = brightness + fadeAmount*randomNumber;
// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
// wait random time to continue with the dimming effect
delay(random(20,80));
// This routine blinks randoms on/offs, Only enter once in 200 times.
if (random(1,200) == 1 ){
for (int i=0; i <= random(2,6); i++){
analogWrite(led, brightness);
delay(random(10,200));
analogWrite(led, 0);
delay(random(30,700));
}
}
}