const int ledPin = 9; // กำหนดขา LED
const int potPin = A0; // กำหนดขา Potentiometer
void setup() {
pinMode(ledPin, OUTPUT); // ตั้งค่าขา LED เป็น OUTPUT
}
void loop() {
int potValue = analogRead(potPin); // อ่านค่าจาก potentiometer
int ledBrightness = map(potValue, 0, 1023, 0, 255); // แปลงค่าจาก 0-1023 เป็น 0-255
analogWrite(ledPin, ledBrightness); // ควบคุมความสว่างของ LED
delay(100); // รอสักครู่
}