1int ledPin = 9; // PWM pin for the LED
2
3void setup() {
4 // Start serial communication at 9600 baud rate
5 Serial.begin(9600);
6 pinMode(ledPin, OUTPUT);
7}
8
9void loop() {
10 // Check if Python is sending data
11 if (Serial.available() > 0) {
12 // Read the incoming byte (0 to 255)
13 int brightness = Serial.read();
14
15 // Apply the brightness to the LED
16 analogWrite(ledPin, brightness);
17 }
18}
19