Go Down

Topic: Entering multiple Steps with variable speed and time then save to EEPROM (Read 114 times) previous topic - next topic

Syameer25

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:
Code: [Select]
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.

lastchancename

I'd use a struct for each step, and an array of those structs for the sequence.
To make it more flexible, make the array a linked list or write code to insert/delete or move steps.
You could also save sequences to EEPROM or later recall.
Experienced responders have a nose for laziness, (they were beginners once)... Sure, there are trolls, chest-beaters, and pretenders - but the help you'll get here is about as good as it gets - if you try to help youself!.

Syameer25

Hi thanks for the suggestion, actually can you give me a rough sketch sir, so i get the idea. Or is it like the user enter how many steps first then i can use FOR as the max steps (i.e: for(i =0, i<steps,i++) and using array for each speed and time repestively? sorry for the short coding, i have no laptop near me.

lastchancename

When I do something similar, I keep  track of the current position, and When  I set a new target position, I just let loop take care of the stepping without a need for me to anything else.   If I change the target, it simply chases that value, keeping the current position updated with each step
Experienced responders have a nose for laziness, (they were beginners once)... Sure, there are trolls, chest-beaters, and pretenders - but the help you'll get here is about as good as it gets - if you try to help youself!.


Go Up