#define POTENT_PIN A0
#define RED_LED 4
#define GREEN_LED 3
#define BLUE_LED 2
int leds[3] = { RED_LED, GREEN_LED, BLUE_LED };
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.write("Read Input Voltage from potentiometer\n");
pinMode(RED_LED, OUTPUT);
pinMode(GREEN_LED, OUTPUT);
pinMode(BLUE_LED, OUTPUT);
pinMode(POTENT_PIN, OUTPUT);
}
void lighUp_led(int index) {
digitalWrite(leds[index], HIGH);
delay(350);
digitalWrite(leds[index], LOW);
}
void loop() {
// put your main code here, to run repeatedly:
int sensorValue = analogRead(POTENT_PIN);
double voltage = sensorValue * (3.0 / 1023.0);
int ledIndex = map(sensorValue, 0, 1023, 0, 2);
lighUp_led(ledIndex);
Serial.println("\nLit up pin number");
Serial.print(ledIndex);
}