Re: Input and storing a number from Keypad

I want to store a 10digit number like 012562134 , which i will be entering from the keypad . But when i press # to register my number it not working..the other keypad is working well except # button

I want to store a 10digit number like 012562134 , which i will be entering from the keypad . But when i press # to register my number it not working…the other keypad is working well excep # button

here is my code…

#include <SoftwareSerial.h>

#include <TinyGPS.h>

#include <Keypad.h>
SoftwareSerial Gsm(11,10);
TinyGPS gps; //create a new instance of the TinyGPS object
boolean SMSRequest();
char incomingChar;

const byte ROWS = 4;
const byte COLS = 4;

char phoneNum[12]="";

int x=0;

char keys[ROWS][COLS] = {
{‘1’,‘2’,‘3’,‘A’},
{‘4’,‘5’,‘6’,‘B’},
{‘7’,‘8’,‘9’,‘C’},
{’*’,‘0’,’#’,‘D’},
};

byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2};//connect to the column pinouts of the keypad
int count=0;

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
char entryStr[11];
int i=0;

void setup()
{
Serial.begin(9600);
Gsm.begin(38400);
Serial.println(“Please register your number first to get the sms of the location.”);
Serial.println("Enter your mobile number: ");

}

void loop()
{
int key = keypad.getKey();

if (key!=NO_KEY && key!=’#’ && key!=’*’)
{

phoneNum = key;
phoneNum[x+1] =’\0’;
x++;
Serial.println(“Press # to register your number”);
Serial.print(phoneNum);

}
if (key==’#’&& x>12)
{
x=0;
i=0;

Serial.println("/rInvalid number/r/n");
Serial.print("/r11 digits only");

}
else if (key==’*’)
{
x–;
phoneNum = 0;

}
else if (key==’#’&& x==12)
{
x=0;
i=0;
Serial.print(phoneNum);
delay(500);
}

bool newData = false;
unsigned long chars;
unsigned short sentences, failed;

if (SMSRequest())
{
// For one second we parse GPS data and repor some key values
for (unsigned long start = millis(); millis() - start <1000;)
{
while (Serial.available())

{
char c = Serial.read();
Serial.print(c);
if (gps.encode(c))
newData = true;
}
}

if (newData) //if newData is true
{
float flat, flon;
unsigned long age;
gps.f_get_position(&flat, &flon, &age);
Gsm.print(“AT+CMGF=1\r”);
delay(400);
Gsm.print(“AT+CMGS=”");
Gsm.print(phoneNum);
Gsm.println(""");

delay(300);
Gsm.print(“Here’s your bicycle location http://maps.google.com/maps?q=loc:”);
Gsm.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
Gsm.print(",");
Gsm.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
delay(200);
Gsm.println((char)26); //End AT command with a ^Z, ASCII code 26
delay(200);
Gsm.println();
delay(200);
exit(0);

}
}
}

boolean SMSRequest() {
if(Gsm.available() >0) {
incomingChar=Gsm.read();
if(incomingChar==‘R’) {
delay(10);
Serial.print(incomingChar);
incomingChar=Gsm.read();
if(incomingChar ==‘o’) {
delay(10);
Serial.print(incomingChar);
incomingChar=Gsm.read();
if(incomingChar==‘U’) {
delay(10);
Serial.print(incomingChar);
incomingChar=Gsm.read();
if(incomingChar==‘T’) {
delay(10);
Serial.print(incomingChar);
incomingChar=Gsm.read();
if(incomingChar==‘E’) {
delay(10);
Serial.print(incomingChar);
Serial.print("\r\nYour Request Has Been Received. Wait to get the location.\r\n");
return true;
}
}
}
}
}
}
return false;
}

complete_code.ino (3.48 KB)

Split from an old topic

char code = keypad.getKey();
if(code != 0)
{
    if(flag == false)
    {
          myCode[i] = code;
          i++;
          if(i == 10)
          {
              flag = true;   //10 digits are received and stored
          }
    }
    else
    {
        if(code == '#')   //display code when # is found
        {
            myCode[i] = '\0';     //null byte is added
            Serial.print(myCode)  //shows: 10-digit code
            flag = false;
        }
    }
}