Hello, I'm having this error (I will transcribe full at the end) when I compile the following code...
It is pretty simple... I have a 3x4 keypad and an LCD display with I2C communication.
When I press a key, it is displayed on the LCD.
I need to convert the char given by the keypad to int, so I can work with these numbers (actually, I need to make a single number with every key I press until I press '*' or '#').
The problem is in the function atoi(), but I don't know how to solve it...
#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);//LCD adress
int cursor=0;
int n=0;
char keyy;
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {13, 12, 11, 9}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
lcd.begin(16,2); //Display initialization
Serial.begin(9600);
}
void loop(){
lcd.setCursor(0,0); //Locate cursor
lcd.write("Ingresar numero");
char key=keypad.getKey(); //Get keypad number
lcd.setCursor(cursor,1);
if(key){ //If key is pressed, write it on display and move cursor
if(key!='#'&&key!='*'){ //Write only numbers
lcd.write(key);
Serial.print(key, DEC); //Verification line. Not necessary when code is ready
n=atoi(key);
Serial.println(n, DEC);
}
cursor++;
}
if(key=='#'){ //Key # is data end.
cursor=0;
lcd.setCursor(cursor,1); //Relocate cursor
lcd.clear(); //Clear display
}
}