Go Down

Topic: faiding raindrop (Read 1 time) previous topic - next topic

Liliortiz

 Raindrop light. this is a light that i created it is a dimmer light that gets brighter and dimmer. in the shape of a raindrop.
Code: [Select]

/*
Fade

This example shows how to fade an LED on pin 9
using the analogWrite() function.

This example code is in the public domain.

*/
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by
int rPin= 9;
int gPin=10;
int bPin=11;

void setup()  {
 // declare pin 9 to be an output:
 //pinMode(9, OUTPUT);
}

void loop()  {
 // set the brightness of pin 9:
 analogWrite(rPin, brightness);
 analogWrite(gPin, brightness);
 analogWrite(bPin, brightness);

 // change the brightness for next time through the loop:
 brightness = brightness + fadeAmount;

 // reverse the direction of the fading at the ends of the fade:
 if (brightness == 0 || brightness == 255) {
   fadeAmount = -fadeAmount ;
 }    
 // wait for 30 milliseconds to see the dimming effect    
 delay(30);                            
}

robtillaart


Looks promising!

You could smear the delay(30) in three parts of delay(10) between the different LEDS, giving it an even smoother feeling

Code: [Select]
analogWrite(rPin, brightness);
  delay(10);
  analogWrite(gPin, brightness);
  delay(10);
  analogWrite(bPin, brightness);
  delay(10);

give it a try

and then read the blink without delay example to learn how to do the same trick without using delay at all so you can add more tasks in parallel
- http://arduino.cc/en/Tutorial/BlinkWithoutDelay - probably the most referenced example code :)
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up