#define P A5
int Led[] = {3, 4, 5, 6};
int index = 4;
int indexnyala = 0;
int Value = 0;
int TIME = 0;
void setup() {
Serial.begin(9600);
pinMode(Led[0], OUTPUT);
pinMode(Led[1], OUTPUT);
pinMode(Led[2], OUTPUT);
pinMode(Led[3], OUTPUT);
}
void loop() {
Value = analogRead(P);
if (Value >= 515 && Value <= 1023) {
TIME = map(Value, 565, 1023, 300, 50);
} else if (Value >= 0 && Value < 490) {
TIME = map(Value, 0, 542, 1023, 300);
}
if (Value >= 490 && Value <= 515){
return;
}
if (Value > 515){
digitalWrite(Led[0], LOW);
digitalWrite(Led[1], LOW);
digitalWrite(Led[2], LOW);
digitalWrite(Led[3], LOW);
indexnyala--;
if (indexnyala < 0){
indexnyala = index - 1;
}
} else if (Value < 490){
digitalWrite(Led[0], LOW);
digitalWrite(Led[1], LOW);
digitalWrite(Led[2], LOW);
digitalWrite(Led[3], LOW);
indexnyala++;
if (indexnyala >= index){
indexnyala = 0;
}
}
digitalWrite(Led[indexnyala], HIGH);
delay(TIME);
Serial.print("Potensio = ");
Serial.print(Value);
Serial.print("\t Hasil = ");
Serial.print(TIME);
Serial.println(" mV");
}