Hi I have a problem with how to let a user insert a 'Step' that has speed (rpm) and time (seconds). What I have done is, the code run for a single time. I want it to run to how many steps needed by the user and store inside EEPROM. Example, user enter Step 1: Speed=4000rpm Time=20sec, save, then Step 2: Speed=3500rpm Time=30sec,save then,...until...,Step 20(max step can be entered): Speed=18000rpm Time=15sec, save, then user can press start button to send data to motor start as shown in my coding
This is the part I think I lack of knowledge:
switch (currentState)
{
case ST_DISPLAY_SETMENU:
// display main menu
displayMenu();
// switch to wait state
currentState = ST_WAIT;
break;
case ST_WAIT:
//get key
key = getKeyWithEcho();
// if speed setting selected
if (key == '1')
{
// display 'step' menu
displayStepMenu();
// change to state where user can enter step
currentState = ST_SETSTEP;
}
// if timing setting selected
if (key == '2')
{
// display 'speed' menu
displaySpeedMenu();
// change to state where user can enter speed
currentState = ST_SETSPEED;
}
// if timing setting selected
if (key == '3')
{
// display 'timing' menu
displayTimingMenu();
// change to state where user can enter timing
currentState = ST_SETTIMING;
}
if (key == '4')
{
//save to EEPROM
eeprom_write();
//displaySummaryMenu(); //display Summary menu
//change to state where user can see the summary of the data
//currentState = ST_SUMMARY;
}
break;
case ST_SETSTEP: //input step menu
// get the text entered on the keypad
text = getKeypadText();
// if text complete
if (text != NULL)
{
// if user did enter a speed
if (text[0] != '\0')
{
theStep = atoi(text);
}
currentState = ST_DISPLAY_SETMENU;
}
break;
case ST_SETSPEED:
// get the text entered on the keypad
text = getKeypadText();
// if text complete
if (text != NULL)
{
// if user did enter a speed
if (text[0] != '\0')
{
theSpeed = atoi(text);
}
currentState = ST_DISPLAY_SETMENU;
}
break;
case ST_SETTIMING:
// get the text entered on the keypad
text = getKeypadText();
// if text complete
if (text != NULL)
{
// if user did enter a speed
if (text[0] != '\0')
{
theTiming = atoi(text);
/*runMotor(MOTOR_START);*/
}
currentState = ST_DISPLAY_SETMENU;
}
break;
/*case ST_STARTMOTOR: //not using at the moment
{
runMotor(MOTOR_START);
currentState = ST_DISPLAY_SETMENU;
}
break;
*/
} // end_of_switch
}
Code is too long so I attach the file for revisions. Sorry for my bad english.
V6.ino (17.9 KB)