Created
May 11, 2013 00:36
-
-
Save volca/5558422 to your computer and use it in GitHub Desktop.
Dimmer for arduino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment