// Potentiometer is connected to A0
#include <LiquidCrystal_I2C.h>
int LEDpins[] = {3, 8, 13};
int Blue = LEDpins[0];
int Green = LEDpins[1];
int Red = LEDpins[2];
#define I2C_ADDR 0x27
#define LCD_COLUMNS 16
#define LCD_LINES 2
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
void setup()
{
lcd.init();
//lcd.backlight();
lcd.backlight(); // turn on backlight of lcd
// put your setup code here, to run once:
Serial.begin(9600); // Initialize serial communication
for(int x=0; x<3; x++)
{ // open for loop
pinMode(LEDpins[x], OUTPUT);
}// close for loop
}
void loop()
{
// put your main code here, to run repeatedly:
int sensorValue = analogRead(A0); // Read the analog value from pin A0
double voltage = sensorValue* (double)5/1023;
//voltage = sensorValue* (double)5/1023;
Serial.print("Potentiometer Value: ");
Serial.println(voltage);
Serial.print("corresponding Digital value: ");
Serial.println(sensorValue); // Print the value to the serial monitor
lcd.setCursor(0, 0); //cell,row
lcd.print("Input= ");
lcd.print(voltage);
lcd.setCursor(0, 1); //cell,row
lcd.print(" ");
lcd.setCursor(0, 1); //cell,row
lcd.print("digital= ");
lcd.print(sensorValue);
delay(500); // Wait for 500 milliseconds
if( voltage < 1.5)
{
digitalWrite(Blue, HIGH);
digitalWrite(Green, LOW);
digitalWrite(Red, LOW);
}
else if( (voltage >= 1.5) && (voltage <= 4))
{
digitalWrite(Green, HIGH);
digitalWrite(Blue, LOW);
digitalWrite(Red, LOW);
}
else
{
digitalWrite(Red, HIGH);
digitalWrite(Green, LOW);
digitalWrite(Blue, LOW);
}
/*else
{
digitalWrite(Red, LOW);
digitalWrite(Green, LOW);
digitalWrite(Blue, LOW);
}*/
}