Hello, I'm working on this project where I need to send a text message to a phone number.
I don't want to hard-code the number into the program but for the user to be able to type it in using a keypad and it would be stored in a character array that is then used by the program.
When I try to implement this, I observe that only one digit is stored in the eeprom.
I'm checking this by printing it out.
I have sectioned out the part of the code doing this alone and included here.
#include <LiquidCrystal.h>
#include <Keypad.h>
//#include <SoftwareSerial.h>
#include <EEPROM.h>
//SoftwareSerial mySerial(11, 10); //Rx and Tx respectively
const int buzzer = 12;
int led = 13;
int smokesensor = A0;
char phone[15] = {};
//LCD Config
const int rs = A2, en = A3, d4 = A4, d5 = A5, d6 = 1, d7 = 0;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
//Keypad config
const byte numRows = 4; //number of rows on the keypad
const byte numCols = 4; //number of columns on the keypad
//Keypad map
char keymap[numRows][numCols] =
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[numRows] = {2, 3, 4, 5}; //Rows 0 to 3 //if you modify your pins you should modify this too
byte colPins[numCols] = {6, 7, 8, 9}; //Columns 0 to 3
Keypad myKeypad = Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);
char keypressed;
char phoneno[14] = {};
void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);//set buzzer to output
buzzercall2();
lcd.begin(16, 2); //initialize the LCD
lcd.clear();//clear the lcd screen
//this loop aims to load the contents of the eeprom addresses into the char array "phoneno"
for (int xxp = 0, xyp = 10; xxp < 15; xxp++) {
phoneno[xxp] = EEPROM.read(xyp);
xxp++;
xyp++;
}
lcd.print(phoneno);
Serial.println(phoneno);
delay(2000);
lcd.clear();
}
void loop()
{
keypressed = myKeypad.getKey();
if (keypressed == 'B') {
buzzercall2();
changenumber();
}
if (keypressed == '#') {//to display the number
lcd.clear();
buzzercall2();
lcd.print(phone);
delay(3000);
lcd.clear();
}
}
void changenumber() {
//char plus_sign = '+';
int char_no = 0;//char_no is used to point to the character in "phone" char array
int lcdrow = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Phone no:");
while (keypressed != 'A') {
keypressed = myKeypad.getKey();
if (keypressed != NO_KEY && keypressed >= '0' && keypressed <= '9') {
lcd.setCursor(lcdrow, 1);
lcd.print(keypressed);
phone[char_no] = keypressed;
buzzercall();
char_no++;
lcdrow++;
}
}
buzzercall2();
int xyp = 10;//xyp is used to set the address of the eeprom to be written to
for (int xxp = 0; xxp < 14; xxp++) {//xxp is used both for the for loop
//iteration and for the character in the char array "phone" pointed to
EEPROM.put(xyp, phone[xxp]);
xxp++;
xyp++;
}
xyp = 10;//xyp which has been declared before is used
for (int xxp = 0; xxp < 14; xxp++) {
phoneno[xxp] = EEPROM.read(xyp);
xxp++;
xyp++;
}
Serial.println(phoneno);
}
void buzzercall2 () {
for (int i = 0; i < 2; i++) {
digitalWrite(buzzer, HIGH);
delay(70);
digitalWrite(buzzer, LOW);
delay(15);
}
}
void buzzercall() {
digitalWrite(buzzer, HIGH);
delay(150);
digitalWrite(buzzer, LOW);
}