Go Down

Topic: char key = keypad.getKey(); command interference sms prgramming (Read 2217 times) previous topic - next topic

roy0926

Nov 02, 2012, 06:55 am Last Edit: Nov 02, 2012, 07:40 am by roy0926 Reason: 1
Code: [Select]

#include <Password.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
#include <SoftwareSerial.h>
#include <String.h>
SoftwareSerial mySerial(7, 8);
int fallalert = LOW;

LiquidCrystal lcd(22, 24, 26, 28, 30, 32);
Password password = Password( "4321" );
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
 {'1','2','3','F'},
 {'4','5','6','E'},
 {'7','8','9','D'},
 {'A','0','B','C'},
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = {39, 41, 43, 45}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {31, 33, 35, 37}; //connect to the column pinouts of the keypad
const int buttonPin = 2;
int buttonState = 0;
int count=0;




// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

const int ledPin =  13;

void setup(){
pinMode(buttonPin, INPUT);
lcd.begin(16, 2);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW); // sets the LED OFF
Serial.begin(9600);
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
keypad.setDebounceTime(250);

 mySerial.begin(19200);               // the GPRS baud rate  
 Serial.begin(19200);    // the GPRS baud rate
 delay(500);
 pinMode(12, INPUT);
}



void loop(){
 
  char key = keypad.getKey();
  fallalert = digitalRead(12);
  buttonState = digitalRead(buttonPin);
 
 if (buttonState == HIGH)
  {
    lcd.clear();
  }
 
 if(fallalert == HIGH)
 {
   SendTextMessage();
   Serial.println("t");
  fallalert = LOW;
  delay(2000);
 
 }
 
 if (Serial.available())
   switch(Serial.read())
  {
    case 't':
      SendTextMessage();
      break;

  }
   
 if (mySerial.available())
   Serial.write(mySerial.read());
   
   
}
 ///SendTextMessage()
///this function is to send a sms message
void SendTextMessage()
{
 mySerial.print("AT+CMGF=1\r");    //Because we want to send the SMS in text mode
 delay(100);
 mySerial.println("AT + CMGS = \"+6583989586\"");//send sms message, be careful need to add a country code before the cellphone number
 delay(100);
 mySerial.println("SUCCESSFULLY SEND FROM GPRS");//the content of the message
 delay(100);
 mySerial.println((char)26);//the ASCII code of the ctrl+z is 26
 delay(100);
 mySerial.println();
}

//take care of some special events
void keypadEvent(KeypadEvent eKey)
{
 
switch (keypad.getState())
{
case PRESSED:
lcd.print(eKey);
switch (eKey)
{
case 'E': guessPassword(); break;
default:
password.append(eKey);
}
}
}

void guessPassword(){
if (password.evaluate()){
digitalWrite(ledPin,HIGH); //activates garaged door relay
delay(500);
digitalWrite(ledPin,LOW); //turns off door relay after .5 sec
lcd.setCursor(0, 1);
lcd.print("PASS   "); //
password.reset(); //resets password after correct entry
delay(1000);
lcd.print("Welcome");
delay(2000);
lcd.clear();
}


else{
digitalWrite(ledPin,LOW);
lcd.setCursor(0, 1);
lcd.print("WRONG ");
password.reset(); //resets password after INCORRECT entry
delay(1000);
lcd.clear();
}
}



My project is use arduino uno and sim900. I want make a keypad control and also need send message.


This my code , if I remove char key = keypad.getKey(); command , sms function can work but the keypad function can not work.

Nick Gammon

Read this before posting a programming question


Please edit your post, select the code, and put it between [code] ... [/code] tags.

You can do that by hitting the # button above the posting area.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

roy0926

Code: [Select]
#include <Password.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
#include <SoftwareSerial.h>
#include <String.h>
SoftwareSerial mySerial(7, 8);
int fallalert = LOW;

LiquidCrystal lcd(22, 24, 26, 28, 30, 32);
Password password = Password( "4321" );
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
  {'1','2','3','F'},
  {'4','5','6','E'},
  {'7','8','9','D'},
  {'A','0','B','C'},
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = {39, 41, 43, 45}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {31, 33, 35, 37}; //connect to the column pinouts of the keypad
const int buttonPin = 2;
int buttonState = 0;
int count=0;




// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

const int ledPin =  13;

void setup(){
pinMode(buttonPin, INPUT);
lcd.begin(16, 2);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW); // sets the LED OFF
Serial.begin(9600);
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
keypad.setDebounceTime(250);

  mySerial.begin(19200);               // the GPRS baud rate   
  Serial.begin(19200);    // the GPRS baud rate
  delay(500);
  pinMode(12, INPUT);
}



void loop(){
 
   char key = keypad.getKey();
   fallalert = digitalRead(12);
   buttonState = digitalRead(buttonPin);
 
  if (buttonState == HIGH)
   {
     lcd.clear();
   }
 
  if(fallalert == HIGH)
  {
    SendTextMessage();
    Serial.println("t");
   fallalert = LOW;
   delay(2000);
   
  }
 
  if (Serial.available())
    switch(Serial.read())
   {
     case 't':
       SendTextMessage();
       break;

   }
   
  if (mySerial.available())
    Serial.write(mySerial.read());
   
   
}
  ///SendTextMessage()
///this function is to send a sms message
void SendTextMessage()
{
  mySerial.print("AT+CMGF=1\r");    //Because we want to send the SMS in text mode
  delay(100);
  mySerial.println("AT + CMGS = \"+6583989586\"");//send sms message, be careful need to add a country code before the cellphone number
  delay(100);
  mySerial.println("SUCCESSFULLY SEND FROM GPRS");//the content of the message
  delay(100);
  mySerial.println((char)26);//the ASCII code of the ctrl+z is 26
  delay(100);
  mySerial.println();
}

//take care of some special events
void keypadEvent(KeypadEvent eKey)
{
 
switch (keypad.getState())
{
case PRESSED:
lcd.print(eKey);
switch (eKey)
{
case 'E': guessPassword(); break;
default:
password.append(eKey);
}
}
}

void guessPassword(){
if (password.evaluate()){
digitalWrite(ledPin,HIGH); //activates garaged door relay
delay(500);
digitalWrite(ledPin,LOW); //turns off door relay after .5 sec
lcd.setCursor(0, 1);
lcd.print("PASS   "); //
password.reset(); //resets password after correct entry
delay(1000);
lcd.print("Welcome");
delay(2000);
lcd.clear();
}


else{
digitalWrite(ledPin,LOW);
lcd.setCursor(0, 1);
lcd.print("WRONG ");
password.reset(); //resets password after INCORRECT entry
delay(1000);
lcd.clear();
}
}


My project is use arduino uno and sim900. I want make a keypad control and also need send message.


This is my code , if I remove" char key = keypad.getKey(); "command , sms function can work but the keypad function can not work.

Nick Gammon

Please do not cross-post. This wastes time and resources as people attempt to answer your question on multiple threads.

Threads merged.

I asked you to edit your post. Not to start a totally new thread.

- Moderator
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy