Hello everyone.
Im building a stepper controller to test a few stepper motors I have and because Im kinda new I would like to spice it up by adding a keypad to enter the stepper info and desired speed/distance and a 2 line LCD to display the entries and monitor the output to the stepper. I have played with both the keypad and lcd4bit libraries in the past but never used them together. I know I have a long way to go, but I just started getting my code ideas down. I like to compile and check for errors as I write the code so it doesnt take so long in the end. I have a few issues that I am curious to see what the veterans here have to say about them.
Here's my code so far (far from finished):
#include <LCD4Bit.h>
#include <Keypad.h>
LCD4Bit lcd = LCD4Bit(2);
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'1','2','3','+'},
{'4','5','6','-'},
{'7','8','9','<'},
{'C','0','.','E'}
};
byte rowPins[ROWS] = {3, 2, 1, 0}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7, 6, 5, 4}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad cusomKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
int totalSteps = 0;
int stepSpeed = 0;
int entrydone = 0;
String entry = "";
void setup(){
lcd.init();
lcd.clear();
Serial.begin(9600);
}
void loop(){
//EnterSteps();
//EnterSpeed();
}
void GetEntry(){
entrydone = 0;
if (entrydone = 0){
char key = cusomKeypad.getKey();
if (key != NO_KEY){
switch (key) {
case '+':
break;
case '-':
break;
case '<':
break;
case 'C':
lcd.clear();
lcd.cursorTo(1, 0);
entry = "000";
lcd.printIn("Entry Cleared");
break;
case '.':
lcd.clear();
lcd.cursorTo(1, 0);
lcd.printIn("Invalid Keypress");
delay(1000);
break;
case 'E':
if (entry == "000"){
lcd.clear();
lcd.cursorTo(1, 0);
lcd.printIn("Invalid Entry");
delay(1000);
//possible break needed here?
}
else {
entrydone++;
}
break;
}
//lcd.printIn(" " + key);
entry = String(entry + key);
}
}
}
void EnterSteps(){
if (totalSteps != 0){
lcd.clear();
lcd.cursorTo(1, 0);
lcd.printIn("Enter Steps Per");
lcd.cursorTo(2, 0);
lcd.printIn("Revolution:");
lcd.cursorTo(2, 12);
GetEntry();
if (entrydone = 1){
int x = atoi(entry);
totalSteps = x;
}
}
}
void EnterSpeed(){
if (Speed != 0){
lcd.clear();
lcd.cursorTo(1, 0);
lcd.printIn("Enter Stepper");
lcd.cursorTo(2, 0);
lcd.printIn("Speed:");
lcd.cursorTo(2, 12);
GetEntry();
if (entrydone = 1){
int holder = atoi(entry);
stepSpeed = holder;
}
}
}
}
Currently the errors that I am trying to resolve are where the variables that contain the combined keypad numbers are displayed to the LCD and are set to the variables required by the libraries. I understand the stepper library isn't included yet but im workin on it after the code here is all set.
Here s my error:
sketch_feb16a.cpp: In function 'void EnterSteps()':
sketch_feb16a:88: error: cannot convert 'String' to 'const char*' for argument '1' to 'int atoi(const char*)'
I searched here and found a few previous issues similar to what I have here but I dont really understand the explanations given to the individuals having the problem. I assume its a problem with syntax and I tried a few solutions as they were written for others with no luck. I appreciate any input and I will repost code as this project comes together better in the future.