| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Dimming LEDs

Page history last edited by PBworks 16 years, 9 months ago

Dimming LEDs

This program introduces a way to dim and brighten LEDs using a new command called analogWrite. analogWrite is a way of generating pseudo-analog voltages on a digital pin by using Pulse Width Modulation. PWM is in the simpliest of terms just turning something on and off so fast that it appears to dim or brighten.

 

NOTE: This only works on those pins marked PWM (11, 10, 9, 6, 5, 3).

 

/*  PWM Output

    Using PWM to dim and brighten an LED

    PG35 Programming Notebook

*/

int ledPin  =  9;     // PWM pin for the LED

void setup(){}        // no setup needed

void loop()

{

  for (int i=0; i<=255; i++)  // ascending value for i

  {

    analogWrite(ledPin, i);   // sets brightess level to i

    delay(100);               // pauses for 100ms

  }

  for (int i=255; i>=0; i--)  // descending value for i

  {

    analogWrite(ledPin, i);   // sets brightess level to i

    delay(100);               // pauses for 100ms

  }

}

Comments (0)

You don't have permission to comment on this page.