#define LED_PIN 2
#define POT_PIN 12
char keterangan[50];
int potValue = 0;
void setup() {
// put your setup code here, to run once:
pinMode(LED_PIN, OUTPUT);
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
// range potValue = 0-4095 (12 bit)
// range brightness = 0-255(8 bit)
potValue = analogRead(POT_PIN);
int brightness = map(potValue, 0, 4095, 0, 255);
analogWrite(LED_PIN, brightness);
sprintf(keterangan, "Tingkat kecerahan lampu = %d", brightness);
Serial.println(keterangan);
}