# SOLVED - How do I shift origin (or what it's called)?

Hello everyone! I am new to this and I am doing my first project and I encounter the problem of not having anything to write at all! :’(

Anyways, I am doing something like this: I want pot1 to set some number (0-1023) and pot2 to be an adjustment pot and set number 512 (middle position of the pot2) as its zero(origin). Print pot1 and pot2 values to the serial monitor.

So if pot1 is at 0, and pot2 is also at 512, LCD output will be 0.
If pot1 is at 800, and pot2 is at 512, still LCD output is at 800.
If pot1 is at 800, and pot2 is at 812, LCD output is at 1100 (from 800+300).
If pot1 is at 800 and pot2 is at 212, LCD output will be 500.
If pot1 is at 100 and pot2 is at 212, LCD output is at -200.
If pot1 is at 0, and pot2 is at 0, LCD will output -512.

So basically, I want to shift origin of numbers. Pot1 is the number and pot2 is the adjuster. How should I do this?

I appreciate your guidance my gurus. Thank you all.

Here is my code that I can’t even finish:

``````#include <LiquidCrystal.h>              //Load Liquid Crystal library
LiquidCrystal lcd(10, 9, 5, 4, 3, 2);   //Create Liquid Crystal object as LCD
int pot1= A0;                           //Declare variable and set to A0  (from 0 to 1023)
int pot2= A1;                           //Declare variable and set to A1  (from 0 to 1023)
int potValue1;                          //Declare variable to store pot1 value
int potValue2;                          //Declare variable to store pot2 value

void setup() {
pinMode(pot1, INPUT);         //Set as input
pinMode(pot2, INPUT);         //Set as input
Serial.begin(9600);           //Start serial com at baud rate 9600
lcd.begin(16,2);              //Start LCD 16x2
lcd.setCursor(0,0);           //Start printing at 0,0
lcd.print("Value: ");         //Print message
}

void loop() {
Serial.print(potValue1);    //Print potValue1 to serial monitor at left side
Serial.print(" | ");        //Print space in between potValue1 and potValue2
Serial.println(potValue2);  //Print potValue2 to serial monitor at right side
/*
* What should I write here?
*/
lcd.setCursor(0,1);           //Start printing at 0,1
delay(250);
}
``````

Isn't the value you want simply (potValue1 + (potValue2 - 512))?

Steve

``````analogRead(A0);

value = pot1 + (pot2 - 512);
``````

reading a port twice helps to stabilize it, otherwise you could read it multiple times and average them.

If you want the second pot for fine-tuning you could do something like this

float value = pot1 + ((pot2 - 512.0) / 512.0 * (pot1 * 0.1) );

now the range of pot2 is always ± 10% of pot1 (adjust 0.1 for other percentage)

Another variation I saw once (for KHz adjustment) was

float KHz = (pot1 * 10) + (pot2 * 0.1);

Wow! Thank you so much guys. I thought this is very difficult but you guys did it with a math without a hitch!

This problem is solved! Arigatou!