Skip to content

Instantly share code, notes, and snippets.

@shfitz
Last active April 11, 2023 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shfitz/d65f25e1c7852a67b36d7e1feaa0108f to your computer and use it in GitHub Desktop.
Save shfitz/d65f25e1c7852a67b36d7e1feaa0108f to your computer and use it in GitHub Desktop.
const int ledPin = 2; // 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() {
int bright;
// check if data has been sent from the computer:
if (Serial.available()>0) {
// read the most recent byte (which will be from 0 to 255):
bright = Serial.read();
// set the brightness of the LED:
analogWrite(ledPin, bright);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment