Last active
April 11, 2023 13:37
-
-
Save shfitz/d65f25e1c7852a67b36d7e1feaa0108f to your computer and use it in GitHub Desktop.
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 = 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