Keypad to LCD

Hey guys I am trying to get a keypad to input onto an LCD. I want the value to always be 6 characters long and to have 3 decimal places showing. when I enter a key, I want the 3rd decimal place to take the character of the key and each of the previous characters to slide 1 position to the left. ie if the screen is showing “76.532” and I use the keypad to enter the number “1”. I want the display to drop the seven, shift all the numbers one spot to the left, and insert a “1” on the end. this would give me the number “65.321”.

ignore the millis(). that is just there so I can ref a reset.

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins

LiquidCrystal lcd(8, 9, 10, 11, 12, 13);//RS,EN,D4,D5,D6,D7

#include <Keypad.h>//header for keypad commands enabling

const byte ROWS = 4; // Four rows

const byte COLS = 4; // Three columns


// Define the Keymap

char keys[ROWS][COLS] = {

  {'1','2','3','A'},

  {'4','5','6','B'},

  {'7','8','9','C'},

  {'#','0','*','D'}

};

// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.

byte rowPins[ROWS] = { 4,5,6,7 };

// Connect keypad COL0, COL1 and COL2 to these Arduino pins.

byte colPins[COLS] = { 0,1,2,3 };

//  Create the Keypad

Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

char a=1;
float b=.02;
float c=.3;
float e=5;
float f=60;
float ReturnPostionVar = a+b+c+e+f;

void setup()

{
  lcd.begin(16, 2);//initializing LCD
  lcd.print("Return Pos");
  lcd.setCursor(0,1);
  lcd.print(ReturnPostionVar);
}

void loop()

{
  char key = kpd.getKey(); //storing pressed key value in a char
  if (key != NO_KEY)
{
 lcd.setCursor(0,1);
 lcd.print("");
float f=e*10;
float e=c*10;
float c=b*10;
float b=a*10;
float a=key*.001;
float ReturnPostionVar=a+b+c+e+f;
 lcd.leftToRight();
      lcd.print(ReturnPostionVar); //showing pressed character on LCD
  }
  lcd.rightToLeft();
lcd.setCursor(15,1);
lcd.print(millis()/1000);
}
    float a = key * .001;

The program already has a problem because key is an ASCII character not a number. So when you press 1, key actually holds 49 in decimal. To convert the ASCII code for a number to its actual number subtract '0'

UKHeliBob are you saying it needs to be like below?

float a = ( key - 0 ) * .001;

It helps to have an ASCII table handy while thinking about this. Observe the decimal values for the various characters. Note that the numerals 0-9 are not represented with their actual values. That is, the numeric value 3 is not represented as b00000111. So, subtracting a numeric value of zero ( all bits off ) from an ASCII ‘1’ will leave you with the original value. Subtracting an *ASCII * ‘0’ however…

Thank you guys for helping through that. Does it hold the number as an actual number now? I am going to be comparing it to a sensor value.

So it is scrolling right to left as i want it to and it is keeping the numbers as expected but it will only hold 2 decimal places. I can not get it to show the third?

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins

LiquidCrystal lcd(8, 9, 10, 11, 12, 13);//RS,EN,D4,D5,D6,D7

#include <Keypad.h>//header for keypad commands enabling

const byte ROWS = 4; // Four rows

const byte COLS = 4; // Three columns


// Define the Keymap

char keys[ROWS][COLS] = {

  {'1','2','3','A'},

  {'4','5','6','B'},

  {'7','8','9','C'},

  {'#','0','*','D'}

};

// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.

byte rowPins[ROWS] = { 4,5,6,7 };

// Connect keypad COL0, COL1 and COL2 to these Arduino pins.

byte colPins[COLS] = { 0,1,2,3 };

//  Create the Keypad

Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

float a=.001;
float b=.01;
float c=.1;
float e=0;
float f=10;
float ReturnPostionVar = a+b+c+e+f;

void setup()

{
  lcd.begin(16, 2);//initializing LCD
  lcd.print("Return Pos");
  lcd.setCursor(0,1);
  lcd.print(ReturnPostionVar);
}

void loop()

{
  char key = kpd.getKey(); //storing pressed key value in a char
  if (key != NO_KEY)
{
 lcd.setCursor(0,1);
 lcd.print("");
 f = e*10;
 e = c*10;
 c = b*10;
 b = a*10;
 a = (key-48) *0.001;
 ReturnPostionVar=a+b+c+e+f;
 lcd.leftToRight();
      lcd.print(ReturnPostionVar); //showing pressed character on LCD
  }
  lcd.rightToLeft();
lcd.setCursor(15,1);
lcd.print(millis()/1000);
}

Does it hold the number as an actual number now?

Don't you know? Print whatever variable you are waving your arms about, and see what it contains. Is that what you expect?