//--scary lights pwm test v 2.0 //--This code is based on the work of: /* Ernst Christensen 16.okt. 2011, taken from >> http://arduino.cc/forum/index.php/topic,75334.0.html Edited by Hannah March 2012 >> http://www.kobakant.at/DIY/?p=3393 Super Spooky Evil Eyes of Doom Revison by Matt Pearson September 2012 >>instructables.com */ int led[]={0,1,2,3,4}; int count=0; int delayTime = 40; void setup()//--set all pins to output { for (int x=0;x<5;x++){ pinMode(led[x],OUTPUT); } } void spwm(int freq,int spin,int sp){ //--on digitalWrite(spin,HIGH); delayMicroseconds(sp*freq); //--off digitalWrite(spin,LOW); delayMicroseconds(sp*(255-freq)); } //spwm void loop() { delayTime= random(3,80);// Set values between 2 and 80 -- How long LED stays on count= (random(0,5)); // Fading On-- for (int x=1;x<254;x++) { spwm(x,led[count],delayTime); } //--Fading Off for(int x=254;x>1;x--) { spwm(x,led[count],4); //--the last argument can be "delayTime" variable if you want to fade out same way as you faded on. //--Setting it to 1 or 2 turns off lights real fast like the eyelid is closing } count= random(0,2); delay(random(100,9000));//--- amount of time leds are OFF before next eye turns on 9 seconds is pretty long but makes it harder to locate the eyes }