const int ledPin = 2; // GPIO pin connected to the LED
void setup() {
Serial.begin(9600); // Initialize serial communication
pinMode(ledPin, OUTPUT); // Set LED pin as output
}
void loop() {
if (Serial.available() > 0) { // Check if serial data is available
int intensity = Serial.parseInt(); // Read the integer value from serial
intensity = constrain(intensity, 0, 255); // Constrain the value between 0 and 255
analogWrite(ledPin, intensity); // Set LED brightness using PWM
}
}