SOLVED "Translated" potentiometer values on an LCD?

Hello,
Newbie question. I am using the following code to display the values from a potentiometer on an LCD display and meter (the meter part works fine). It is working well, the LCD displays the values from the potentiometer properly. My question is, is it possible to use those values and have the LCD display show alternate figures for the values? So instead of 0-1021, could it display the values on a scale of 1 to 5? The values arriving from the pot remain the same but they are "translated" on the display to a number from 1 to 5?

I'm sorry if this is a silly question, I am fairly new to Arduino programming. Also, any basic corrections to the code would be appreciated.


#include <LiquidCrystal.h> // include the library code
#define MeterPin 5
#define PotentiometerPin A1

LiquidCrystal lcd(13, 12, 11, 10, 9, 8); // initialize the library with the numbers of the interface pins

void setup() 
{
  pinMode(MeterPin, OUTPUT);
  lcd.begin(16, 2); // set up the LCD's number of columns and rows
  Serial.begin(9600);
}

void loop() 
{
  int potentiometerValue = analogRead(PotentiometerPin);
  int power = map(potentiometerValue, 0, 1021, 0, 255);
  analogWrite(MeterPin, power);
  lcd.setCursor(6, 0); // set the cursor to column 6, line 0
  lcd.print(potentiometerValue); // print out the value on LCD Display
  analogWrite(MeterPin, power);
  delay(1000);
  lcd.clear();  
}

Not a silly question at all. This is done all the time. Look at the "map()" instruction.

1 Like

Yes, in the code you posted! It is already demonstrated for you…

Tip: don't just cut and paste code. Read code you steal borrow. It's a good way to see how ppl do stuff.

a7

1 Like

Of course, the map() instruction will work for both, I should have thought of that. Thank you for taking the time to answer.

Thanks for taking the time to answer.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.