Hello everyone,
I'm stuck here for quite abit, Please take a look at my code and assist me with some inputs!!
I'm doing a keypad that takes in your hp number and stores in an array for the gsm which in turn sends a password to you.
By keying in the randomly assigned password, d10 would send a high signal to trigger my relay.
So far I have done up to this point.
#include <SCoop.h> //multi tasking functions
#include <Wire.h> // low level i2c functions
#include <a_delays.h> // for debouncing
#include <a_i2c.h> // high level i2c functions
#include <a_lcd.h> // lcd uses i2c
#include <a_key.h> // keypad uses i2c
#include <SoftwareSerial.h>
#define IGT 8 // ignition pin
SoftwareSerial mySerial(5, 6); // RX, TX
void password (void);
void getNumber (void);
void gsm (void);
extern char hpbuf[9];
extern int pswbuf[8];
extern int genbuf[8];
void setup()
{
i2cInit(); // called first before keyInitI2c()
keyInitI2c(0x3a); // provide i2c address
lcdInitI2c(0x39); // provide i2c address
Serial.begin(57600); //Baud rate of arduino
pinMode(IGT,OUTPUT);
digitalWrite(IGT,HIGH); //High-Low-High ignition for gsm
delay(100);
digitalWrite(IGT,LOW);
delay(150);
digitalWrite(IGT,HIGH);
delay(100);
Serial.begin(57600);
Serial.println("Enter Handphone number");
Serial.print("HpNumber");
}
void loop() {
uint8_t c, a, i;
lcdClrScr(); //remove previous message on lcd screen
lcdPutStr("Pls enter HP No.");
lcdSetXY(0,1); //bring down hp. number on next line
getNumber(hpbuf); //display keypad input
lcdSetXY(0,0);
lcdPutStr("Press D to send");
a = myKeyGet();
//d = keyChk();
switch(a){
case 'D':
lcdClrScr();
lcdPutStr("Pls Check your phone.");
Serial.println(hpbuf);
gsm();
lcdClrScr();
lcdPutStr("Please Enter PSW.");
delay(5000);
lcdSetXY(0,1);
a = myKeyGet();
// while(1){
//if (password() == ){
//pinMode(10,OUTPUT);
//digitalWrite(10,HIGH);
// }
break;
case 'C':
lcdClrScr();
lcdPutStr("Pls enter HP No.");
hpbuf=0; //reset array to 0
break;
case 'A':
lcdClrScr();
lcdSetXY(0,0);
lcdPutStr("C to clr screen and D for psw.");
delay(5000);
break;
case 'B':
lcdClrScr();
lcdSetXY(0,0);
lcdPutStr("C to clr screen and D for psw.");
delay(5000);
break;
}
}
Next Tab
char hpbuf[9]; //set array to having 8 + 1 digit
char HPNumber[9] = "12345678";
void getNumber(char buf[]){
uint8_t i,a;
Serial.println("Getting Hp Number");
for(i=0; i<=7; i++){ //allows only 8 Digit for Hp Number
a = getDigit();
lcdPutCh(a); // Display Hp Number on lcd
buf=a; // store hp number into array for gsm
}
buf=0; // reset my input hp number
}
uint8_t myKeyGet(void){
uint8_t a;
while(1){
if((a = keyChk())!= NOKEY_CODE){
return a;
}
yield();
}
}
uint8_t getDigit(void){
while(1){ uint8_t c;
c = myKeyGet();
if ( c >= '0' && c <= '9'){
return c;
}
}
}
Next Tab
void chkPsw(char pswbuf[]){
uint8_t i,a;
Serial.println("Getting password");
for(i=0; i<=7; i++){ //allows only 8 Digit for Password
a = getDigit();
lcdPutCh(a); // Display password on lcd
pswbuf=a; // store password into array for checking
}
pswbuf=0; // reset my input password
}
uint8_t myPswGet(void){
uint8_t a;
while(1){
if((a = keyChk())!= NOKEY_CODE){
return a;
}
yield();
}
}
uint8_t getNum(void){
while(1){ uint8_t c;
c = myPswGet();
if ( c >= '0' && c <= '9'){
return c;
}
}
}
As you all can see, after sending a password to the user phone, It returns straight to the entering HP number.
I require the next step of entering the received password to trigger my relay if it is correct.
Thanks for taking your time in the wall of code.
Appreciate all replies.
Moderator edit: Wall of code tags tidied-up.