How can I get a string input from the 4x4 keypad?

The following code gets three input angles from serial communication and writes them as outputs to servo motors. It also does some equations with these input angles and stores the outputs in variables x,y, and z. I wanted to take the input angles from a 4x4 matrix keypad instead of serial communication.
Thank you in advance.

#include <LiquidCrystal.h>
#include <Servo.h>


#define basepin 9           //pins for the servo motors
#define rightpin 14
#define leftpin 15
#define grippin 16

Servo base;
Servo right;
Servo left;
Servo gripper;

#define rs 12               //pins for LCD display
#define en 11
#define d4 5
#define d5 4
#define d6 3
#define d7 2

LiquidCrystal lcd (rs,en,d4,d5,d6,d7);

#define l1  2.6            //length of links measured manually
#define l2  8.85
#define l3  11.4



void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);

lcd.begin(16,2);           //lcd screen dimensions

base.attach(basepin);      //allocating a servo for each pin
right.attach(rightpin);
left.attach(leftpin);
gripper.attach(grippin);

Serial.println("Enter Angle Values");

}

void loop() {
  // put your main code here, to run repeatedly:

  /* Transformation Matrix = [ c1*c2*c3 - c1*s2*s3, - c1*c2*s3 - c1*c3*s2,  s1, c1*c2*l2 - c1*l3*s2*s3 + c1*c2*c3*l3]
                             [ c2*c3*s1 - s1*s2*s3, - c2*s1*s3 - c3*s1*s2, -c1, c2*l2*s1 + c2*c3*l3*s1 - l3*s1*s2*s3]
                             [       c2*s3 + c3*s2,         c2*c3 - s2*s3,   0,   l2*s2 + c2*l3*s3 + c3*l3*s2 + 13/5]
                             [                   0,                     0,   0,                                    1]*/
  
  int thetadeg1 = Serial.parseInt();    //input of angle values in degree from serial communication
  int thetadeg2 = Serial.parseInt();
  int thetadeg3 = Serial.parseInt();


float thetarad1 = thetadeg1*(PI/180);   //degree to rad conversion
float thetarad2 = thetadeg2*(PI/180);
float thetarad3 = thetadeg3*(PI/180);


float c1 = cos(thetarad1);              //renaming the functions for easy reading

float c2 = cos(thetarad2);

float c3 = cos(thetarad3);

float s1 = sin(thetarad1);

float s2 = sin(thetarad2);

float s3 = sin(thetarad3);
 
 
  base.write(thetadeg1);                //writing the input angles onto the servos
  right.write(thetadeg2);
  left.write(thetadeg3);
  gripper.write(180);

 float X = (c1*c2*l2) - (c1*l3*s2*s3) + (c1*c2*c3*l3) ;   //values of x, y, and z from the transformation matrix
 
 float Y = (c2*l2*s1) + (c2*c3*l3*s1) - (l3*s1*s2*s3) ;
 
 float Z = (l2*s2) + (c2*l3*s3) + (c3*l3*s2) + l1 ;

 Serial.print("X = ");                                    //show the coordinates values on Serial monitor
 Serial.println(X);

 Serial.print("Y = ");
 Serial.println(Y);

 Serial.print("Z = ");
 Serial.println(Z);
 Serial.println(" ");
 delay(10000);
 
 int x = X;                                               //show the cordinates on LCD display
  lcd.print("X=");
  lcd.print(x);
  lcd.print(" ");
int y = Y;
  lcd.print("Y=");
  lcd.print(y);
  lcd.print(" ");
int z = Z;
  lcd.print("Z=");
  lcd.print(z);
  lcd.print(" ");
 
lcd.setCursor(0, 0);

}

Welcome to the forum

What have you tried ?

You will need values from '0' to '9' on the keypad, a value, maybe '#' to indicate that entry of a number is complete and another value, say '*' to indicate that all 3 entries have been made

Keypad data entry. A beginners guide may give you some ideas about how to read and use the keypad

You are using 13 I/O pins. Your board has five more I/O pins (17/A3, 18/A4, 19/A5, 20/A6, 21/A7). If you change your LCD from (RS, EN, D4, D5, D6, D7) protocol to I2C (A4/18, A5/19), you will gain four pins, for a total nine pins available.

Keypad matrix use one pin per row and column (add row pins to column pins). To get all nine digits and an "enter" key on a keypad, you would need a 4x3 (7 pins) or 4x4 (8 pins) matrix.

plus pins 0 and 1.

Hi ahmedessam,

welcome to the Arduino-Forum

How do you want to present yourself to the Ardunio-community?
Be aware of, that the other users know nothing about you except the things
you present in your postings.

You might be the most friendly helpful warmhearted guy the kind every mother wants as a son-in-law
If you would post in a certain way you could create the opposite picture.

Depending on the way you do your first posting you can draw very different pictures of yourself.

This picture can be

  • Newcomer that has read the "how to get the best out of this forum" / or the opposite
  • very careful working, very careful preparing a posting / or the opposite
  • beeing very diligent in gathering information / or the opposite
  • having taken time to read the basic introductional information / or the opposite
  • willingness to learn through asking specific questions / or the opposite
  • be diligent in providing information / or the opposite

You don't have to make a perfect first posting. But the more effort you put into it
and the more points you consider that are generally important and do fullfill
the better the picture will be and the better the help will be that you receive.

As you can see from the answers that you got so far.
You have been asked for own effort.
Nobody is willing to modify the code you posted until there is new ready to use code.

You should show own effort by making an attempt to modify the code.
Your attempt does not even have to compile. What counts is your own attempt.
Then ask specific questions related to your attempt.

If you ask in this way you will get always answers. Hundreds of answers if this is nescessary.

You should write how easy it is for you to get additional components.
If you are living in a country on the land where no online-shops deliver to
or
if your budget is very limited
you should say this because then it is possible to suggest solutions that fit to your situation.

best regards Stefan

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