/*
Nama : Maulana Agus Setiawan
NIM : 2209106024
Soal : 2
*/
const int potPin = 14;
int ledPins[] = {35, 36, 37, 38, 39};
void onOffLed(int pin) {
for (int i = 0; i < 5; i++) {
if (ledPins[i] == pin) {
digitalWrite(ledPins[i], HIGH);
} else {
digitalWrite(ledPins[i], LOW);
}
}
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
for(int i = 0; i < 5; i++){
pinMode(ledPins[i], OUTPUT);
}
}
void loop() {
// put your main code here, to run repeatedly:
int tankLevel = map(analogRead(potPin), 0, 4095, 0, 100);
String status;
if (tankLevel < 10) {
status = "KOSONG";
onOffLed(39);
} else if (tankLevel < 30) {
status = "RENDAH";
onOffLed(38);
} else if (tankLevel < 70) {
status = "SEDANG";
onOffLed(37);
} else if (tankLevel < 90) {
status = "TINGGI";
onOffLed(36);
} else {
status = "PENUH";
onOffLed(35);
}
Serial.println(status);
}