Hello, I have been trying to use an Arduino keypad to input values for calculations. The keypad is working, but my conversion from the string to an int is not. When the '#' is pressed on my keypad, it should as an enter key. Any advice on what I can do to convert the string and have the value display on my serial monitor.
#include <Keypad.h>
float inChar;
int value;
int Trig = 2;
int Echo = 3;
int Pressure;
const int ROW_NUM = 4;
const int COLUMN_NUM = 3;
char keys [ROW_NUM] [COLUMN_NUM] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte pin_rows[ROW_NUM] = {4,5,6,7};
byte pin_columns[COLUMN_NUM] = {8,9,10};
Keypad keypad = Keypad(makeKeymap(keys), pin_rows, pin_columns, ROW_NUM, COLUMN_NUM );
String Stud_Tension;
void setup (){
Serial.begin(9600);
Stud_Tension.reserve(32);
pinMode(Echo, INPUT);
digitalWrite(Echo, LOW);
pinMode(Trig, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
}
void loop(){
char key2 = keypad.getKey();
Serial.print(key2);
if (key2 == '*'){
Stud_Tension = "";
}
else if (key2 == '#'){
(Serial.available() > 0); {
int inChar = Serial.read();
Stud_Tension += (char)inChar;
if (isDigit(inChar)) {
Serial.println(Stud_Tension.toInt());
Serial.print("Tension: ");
Serial.println(inChar);
Pressure = inChar/45.7;
Serial.print("Pressure: ");
Serial.println(Pressure);
}
}
}
}