Arduino101 LEDFader

From Twin Cities Maker wiki
Revision as of 02:28, 22 February 2014 by Danbackslide (talk | contribs) (Created page with "Shows the most basic use of the PWM pins – make lights brighter and dimmer. Also introduces the for loop. == Breadboard layout == File:LED Fader_bb.png == Code == <pre...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Shows the most basic use of the PWM pins – make lights brighter and dimmer. Also introduces the for loop.

Breadboard layout

LED Fader bb.png

Code

int ledPin = 11;
int inc = 1;

void setup() {
  // put your setup code here, to run once:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly: 
  for (int i=0; i>-1; i=i+inc){
    analogWrite(ledPin, i);
    if (i==255){
    	inc = -inc;
    }
    if (i==0){
    	inc = -inc;
    }
    delay(10);
  }
}