const int ledPin = 2;
const int potPin = 34;
const int pwmThresholds[] = {0, 64, 192, 255};
const char* statusStrings[] = {"Mati", "Redup", "Terang", "Terang Sekali"};
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(potPin, INPUT);
Serial.begin(115200);
}
void loop() {
int potValue = analogRead(potPin);
int pwmValue = map(potValue, 0, 4095, 0, 255);
analogWrite(ledPin, pwmValue);
int statusIndex = 0;
while (pwmValue > pwmThresholds[statusIndex]) {
statusIndex++;
}
float voltage = potValue * (3.3 / 4095.0);
Serial.print("Adc: ");
Serial.print(potValue);
Serial.print(" - Tegangan: ");
Serial.print(voltage, 2);
Serial.print("V - Status: ");
Serial.println(statusStrings[statusIndex]);
delay(10);
}