ok, I fixed the comparison =='s as mentioned previously (Thanks for that) and added some comments to the top as to what is left.
Here is the code as it stands now (still workin on it lol)
//Josh Nolan
//Stepper Controller
//Started 2/10/11
//Things left:
// 1)find a fix that will convert the numeric keypad entried to integers so they can be used
// by the subroutines and strings so they can be displayed on the LCD as they are entered.
//
// 2)fix the motor start part. Maybe have something like "Vals ok, Press enter to start!"
//
// 3)look into how this thing is going to act after the motor runs finish. can I hold the
// steps per full revolution value and reset the others for reentry? or reset the whole
// thing?
//
// 4)figure out the pin assignments and build it up. If I can use an 328 I will, if not Ill
// hook it up to the Mega.
#include <Stepper.h>
#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);
const int stepsPerRevolution = 200;
Stepper myStepper(stepsPerRevolution, 8,9,10,11); //can i change 'stepsPerRevolution' after init from main loop or setup?
//If I did it from setup would I have to reset somehow?
int stepsToGo = 0; // number of steps the motor has/will take
int stepsToGoOK = 0;
int totalSteps = 0; //Total number of steps, later used as 'stepsPerRevolution'
int totalStepsOK = 0;
int stepSpeed = 0; // holds stepper speed entry from keypad
int stepSpeedOK = 0;
int entrydone = 0; //indicator to tell me that an entry is completed
int toggleReverse = 0;
int runCount = 0;
String entry = ""; //combined keypad characters to form a int for values
void setup(){
lcd.init();
lcd.clear();
Serial.begin(9600); //for debugging, first time attempting using serial in this manner
}
void loop(){
while (totalStepsOK < 1) {
EnterSteps();}
while (stepSpeedOK < 1) {
EnterSpeed();}
while (stepsToGoOK < 1) {
StepsToGo();}
while (runCount == 0);
RunCounter();}
if (runCount > 0) {
lcd.clear();
lcd.cursorTo(1, 0);
lcd.printIn("Step Initialized");
lcd.cursorTo(2, 0);
delay(1000);
while (runCount > 0) {
lcd.cursorTo(2, 0);
lcd.printIn(runcount);
lc
motorStart();
runCount--;
}
}
char key = cusomKeypad.getKey();
if (key != NO_KEY){
switch (key) {
case 'E': //would like to later use + and - as increment/decrement
lcd.clear();
lcd.cursorTo(1, 0);
lcd.printIn("-Ready to Run-")
delay(1000);
lcd.cursorTo(2, 0);
lcd.printIn("(ENTER to Start)")
break;
case 'C':
break;
}
}
}
void GetEntry(){ //universal entry getter to be called on for values
entrydone = 0;
if (entrydone == 0){
char key = cusomKeypad.getKey();
if (key != NO_KEY){
switch (key) {
case '+': //would like to later use + and - as increment/decrement
break;
case '-':
if (totalStepsOK == 1) {
if (stepSpeedOK == 1) {
if (toggleReverse == 0){
toggleReverse = 1;
}
if (toggleReverse == 1){
toggleReverse = 0;
}
}
}
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++;
Serial.print("Entry Completed");
}
break;
}
//lcd.printIn(" " + key);
Serial.println(key);
entry = String(entry + key);
}
}
}
void EnterSteps(){ //To get the Total number of steps per revolution of motor under test
int x;
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;
Serial.print("EnterSteps ok");
}
}
}
void EnterSpeed(){ //To get motor Speed (Range - 0 to ???) range has to be filtered to usable values
int y;
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 y = atoi(entry);
stepSpeed = y;
Serial.println("EnterSpeed ok");
}
}
void StepsToGo(){
lcd.clear();
lcd.cursorTo(1, 0);
lcd.printIn("Enter Steps to Go");
lcd.cursorTo(2, 0);
lcd.printIn("(- for rev)");
lcd.cursorTo(2, 12);
GetEntry();
}
void RunCounter(){
lcd.clear();
lcd.cursorTo(1, 0);
lcd.printIn("Enter Number of");
lcd.cursorTo(2, 0);
lcd.printIn("Motor Runs:");
lcd.cursorTo(2, 12);
GetEntry();
if (entry > 0){
entry = runCount;
}
else{
lcd.clear();
lcd.cursorTo(1, 0);
lcd.printIn("Need + Run Count");
}
}
void motorStart() { //I want to move-it move-it! lol
if (toggleReverse = 1){
myStepper.step(-stepsToGo);
}
else{
myStepper.step(stepsToGo);
}
}