~ubuntu-branches/debian/experimental/arduino/experimental

« back to all changes in this revision

Viewing changes to build/shared/examples/1.Basics/Fade/Fade.pde

  • Committer: Package Import Robot
  • Author(s): Scott Howard
  • Date: 2012-03-11 18:19:42 UTC
  • mfrom: (1.1.5) (5.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20120311181942-be2clnbz1gcehixb
Tags: 1:1.0.1~rc1+dfsg-1
New upstream release, experimental.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 Fade
3
 
 
4
 
 This example shows how to fade an LED on pin 9
5
 
 using the analogWrite() function.
6
 
 
7
 
 This example code is in the public domain.
8
 
 
9
 
 */
10
 
int brightness = 0;    // how bright the LED is
11
 
int fadeAmount = 5;    // how many points to fade the LED by
12
 
 
13
 
void setup()  { 
14
 
  // declare pin 9 to be an output:
15
 
  pinMode(9, OUTPUT);
16
 
17
 
 
18
 
void loop()  { 
19
 
  // set the brightness of pin 9:
20
 
  analogWrite(9, brightness);    
21
 
 
22
 
  // change the brightness for next time through the loop:
23
 
  brightness = brightness + fadeAmount;
24
 
 
25
 
  // reverse the direction of the fading at the ends of the fade: 
26
 
  if (brightness == 0 || brightness == 255) {
27
 
    fadeAmount = -fadeAmount ; 
28
 
  }     
29
 
  // wait for 30 milliseconds to see the dimming effect    
30
 
  delay(30);                            
31
 
}