Skip to content

Instantly share code, notes, and snippets.

Created May 11, 2013 00:36
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Dimmer for arduino
const int ledPin = 9; // the pin that the LED is attached to
void setup()
// initialize the serial communication:
// 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 =;
// 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