// ตัวอย่าง การเขียนโปรแกรมบอร์ด Multi Function - Arduino uno r3
// MFB LAB15 Pot and led C
// ครูวิบูลย์ กัมปนาวราวรรณ พฤหัสบดี 4 กรกฏาคม 2567
int LED = 10;
int POT = A0; // ใช้ A0 สำหรับ pin analog
void setup() {
Serial.begin(9600);
pinMode(LED, OUTPUT); // ตั้งค่า pin เป็น output
}
void loop() {
int PotValue = analogRead(POT); // อ่านค่า Potentiometer
// แปลงค่า PotValue (0-1023) เป็นค่า PWM (0-255)
int pwmValue = map(PotValue, 0, 1023, 0, 255);
// ใช้ PWM เพื่อปรับความสว่างของ LED
analogWrite(LED, pwmValue);
Serial.print("Potentiometer: ");
Serial.print(PotValue);
Serial.print(" - PWM: ");
Serial.println(pwmValue);
delay(100); // ลดเวลา delay เพื่อให้การตอบสนองเร็วขึ้น
}