Monday, September 13, 2010

Dim by degrees...


//degrees of 0 to 255, LED attached to digital pin 9 and ground
const int ledPin = 9;      // the pin that the LED is attached to  void setup() {   // initialize the serial communication:   Serial.begin(9600);   // initialize the ledPin as an output:   pinMode(ledPin, OUTPUT); }  void loop() {   byte brightness;    // check if data has been sent from the computer:   if (Serial.available()) {     // read the most recent byte (which will be from 0 to 255):     brightness = Serial.read();     // set the brightness of the LED:     analogWrite(ledPin, brightness);   } }

No comments:

Post a Comment