Pages: [1]   Go Down
Author Topic: char key = keypad.getKey(); command interference sms prgramming  (Read 1631 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:

 #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.
« Last Edit: November 02, 2012, 01:40:12 am by roy0926 » Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 495
Posts: 19035
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#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.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 495
Posts: 19035
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged


Pages: [1]   Go Up
Jump to: