Pages: [1]   Go Down
Author Topic: faiding raindrop  (Read 1375 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

  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:
/*
 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);                            
}
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13739
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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:
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 smiley
Logged

Rob Tillaart

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

Pages: [1]   Go Up
Jump to: