hey,
i am working on a project in wich i need to interface a 4x3 keypad to gsm 900a using arduino mega
for sending a txt msg form gsm module on the user specified number enter form the keypad by the user.
and when i am executing my program
i am geting an ERROR
incompatible types in assignment of ‘char’ to 'char [10]
and my program file is attached below plzz help me out if any one can
thankyou…
Let's approach this problem like detectives.
The compiler is telling you that it doesn't like an assignment involving a "char" and a ten element array of "char"s.
char remoteNum[10];// telephone number to send sms
There's the array.
remoteNum = keypad.getKey();
And there's the assignment.
That wasn't so hard, was it?
and when i am executing my program
i am geting an ERROR
No, you are not executing your program, because your program cannot compile.
no it was not so hard but finding the error is very difficul i am struggling this error from
last 2 days.
so what change i should do
to run the program perfectly..??
Well, first, you have to define "perfectly".
Start by deciding what constitutes a phone number, and how you indicate to the Arduino when it is complete.
Here i am declaring the phone number and even its limit to 10 digits
Correct.
and here i am geting the number as input from keypad
That's what the compiler was complaining about.
"getKey" returns a single "char", and you need ten of them.
So, you need to call "getKey" ten times, and you need to assign each "char" returned to a different element of the array.
You can use a for loop if you get the syntax right, but you will also need to make the target array larger in order to incorporate a training zero if you need it to be used as a C style string later in the code, which I expect you do.
You cannot just read 10 keys at once and store them in the char arrays, because your code doesn’t know if you pressed the keys or not… If you call getKey 10 times, it will read 10 times the same key in less than one millisecond… You want your code to check for a new key press and do appropriate actions depending which kkey was pressed ( if key is 0 to 9 store in array, else if key is Validate do something, else if key is Cancel do something else, etc… )
I suggest you read some beginner’s tutorial about C/C++ programming. Then look at the examples of the keypad library that you are using. If that is not sufficient, search on google something like “arduino keypad password” and adapt to your code… If you are lucky you may find an example that does exactly what you want
#include <LiquidCrystal.h>
#include <Keypad.h>
#include <Wire.h>
#define Password_Lenght 10 // Give enough room for six chars + NULL char
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
char Data[Password_Lenght]; // 6 is the number of chars it can hold + the null char = 7
char remoteNumber = 0;
char customKey;
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {
22,24,26,28}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {
30,32,34}; //connect to the column pinouts of the keypad
Keypad customKeypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS); //initialize an instance of class NewKeypad
void setup()
{
lcd.begin(16,2);// initialize the lcd
}
void loop()
{
lcd.setCursor(0,0);
lcd.print("Enter number");
customKey = customKeypad.getKey();
if (customKey) // makes sure a key is actually pressed, equal to (customKey != NO_KEY)
{
Data[remoteNumber] = customKey; // store char into data array
lcd.setCursor(remoteNumber,1); // move cursor to show each new char
lcd.print(Data[remoteNumber]); // print char at said cursor
remoteNumber++; // increment data array by 1 to store new char, also keep track of the number of chars entered
}
}