Typing on lcd like calculator

Hello, I have been trying to make my lcd type like a calculator, when I type a number with my keypad it should start from the right and shift to the left everytime I press an operator or number.
The default is left to right.

I correctly shift num1 to go to the left when I keep adding numbers but the operator and num 2 overlap with num1.
Does anybody know how to do this? Thankyou!

if (currentVal == false) {
      num1 = num1 + keyPress;
      numLen1 = num1.length();
      lcdShift = 20 - numLen1;
      lcd.setCursor(lcdShift, 0);
      lcd.print(num1);
    } else {
      num2 = num2 + keyPress;
      numLen2 = num2.length();
      lcd.setCursor(lcdShift + 2, 0);
      lcd.print(num2);
      endOfOperation = true;
    }
  } else if ((keyPress == '+' || keyPress == '-' || keyPress == '*' || keyPress == '/' ) && currentVal == false && keyPress != NO_KEY)
  {
    if (currentVal == false) {
      currentVal = true;
      operatorr = keyPress;
      lcd.autoscroll();
      lcd.setCursor(lcdShift + 3, 0);
      lcd.print(operatorr);

Please post your best working or not working complete sketch,

It is hard to see how your logic works with no context.

a7

@adrianate

Did you check the set of instructions / functions the lcd libraries has to offer ?

In the datasheet of the lcd display, it does have a command to going from right to left. So I check the library and it does have a function ...
lcd.rightToLeft();

So you have to instruct the lcd the command lcd.rightToLeft(); after the command lcd.setCursor(15,0); ( location of the starting point ) than lcd.print('What Ever"); The default lcd mode is from Left to Right. So change to default if nessary.

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