Skip to main content

I'm working on a project for a robot and I'm trying to make a menu that can run on start up where the user can calibrate the mid-point for the servos (so they're stationary) and the ldrs so it can tell between black lines and white paper. So, I've made the menu a switch case where it calls the calibration when user enters a value, the calibration routines are their own functions. 

What I want to know how to do is how to make it so when the user is finished with a calibrator it will go back to the menu function and also how to get the menu to exit on user input. So far when the menu calls a function it will just loop on it. the menu:

`void Menu(){

Serial.println("||"); Serial.println("||Ardnoid Configuration ||"); Serial.println("|| Menu ||"); Serial.println("||"); Serial.println(""); Serial.println("Select one of the following options:"); Serial.println("1 LDR configuration"); Serial.println("2 Servo calibration"); Serial.println("3 Exit configuration menu");

while(!Serial.available()){} int i = Serial.parseInt();

switch(i){

case 1: break; case 2: while(srvConOn == true){ srvConfig(); } break;strong text case 3: Serial.println("Leaving configuration menu"); break; default: Serial.println("Unrecognized command, try again!"); } }`

and the servo calibrationThe menu:

void srvConfigMenu(){
  
  Serial.println("|****************************|");
  Serial.println("|**|Ardnoid Configuration |**|");
  Serial.println("|**|        Menu          |**|");
  Serial.println("|****************************|");
  Serial.println("");
  Serial.println("Select one of the following options:");
  Serial.println("1 LDR configuration");
  Serial.println("2 Servo calibration");
  Serial.println("3 Exit configuration menu");

  while(!Serial.available()){}
  int i = Serial.parseInt();

  switch(i){

  case 1:
    break;
  case 2:
    while(srvConOn == true){
      srvConfig();
      }
    break;strong text
  case 3:
    Serial.println("Leaving configuration menu"); 
    break;
  default:
    Serial.println("Unrecognized command, try again!");
    } 
 }

Serial.println(""); Serial.println("Beginand the servo stop calibration routine");

int x = 0;

while(x == 0){:

void srvConfig(){

Serial.println("");
Serial.println("Begin servo stop calibration routine");

int x = 0;

  while(x == 0){
    
    Serial.println("Enter values for servos until both are stationary");
    delay(100);

    Serial.println("Enter value for left servo");
    while (!Serial.available()) {;}
    left = Serial.parseInt();
    Serial.println(left);
    delay(100);

    Serial.println("Enter value for right servo");
    while (!Serial.available()) {;}
    right = Serial.parseInt();
    Serial.println(right);
    delay(100);

    srvR.write(right);
    srvL.write(left);

    Serial.println("have both servos stopped?");
    Serial.println("1 = Yes | 2 = No"); 

    int j;
    while (!Serial.available()) {;}
    j = Serial.parseInt();
    
    if (j == 1) {
      Serial.println("Saving calibration");
      EEPROM.write(leftMid, left);
      EEPROM.write(rightMid, right);
      srvConOn == false; 
      x == 1;
      } else if (j == 2) {
        Serial.println("Try again");
        Serial.println();
        }
  }
}

} }

I'm working on a project for a robot and I'm trying to make a menu that can run on start up where the user can calibrate the mid-point for the servos (so they're stationary) and the ldrs so it can tell between black lines and white paper. So, I've made the menu a switch case where it calls the calibration when user enters a value, the calibration routines are their own functions. What I want to know how to do is how to make it so when the user is finished with a calibrator it will go back to the menu function and also how to get the menu to exit on user input. So far when the menu calls a function it will just loop on it. the menu:

`void Menu(){

Serial.println("||"); Serial.println("||Ardnoid Configuration ||"); Serial.println("|| Menu ||"); Serial.println("||"); Serial.println(""); Serial.println("Select one of the following options:"); Serial.println("1 LDR configuration"); Serial.println("2 Servo calibration"); Serial.println("3 Exit configuration menu");

while(!Serial.available()){} int i = Serial.parseInt();

switch(i){

case 1: break; case 2: while(srvConOn == true){ srvConfig(); } break;strong text case 3: Serial.println("Leaving configuration menu"); break; default: Serial.println("Unrecognized command, try again!"); } }`

and the servo calibration:

void srvConfig(){

Serial.println(""); Serial.println("Begin servo stop calibration routine");

int x = 0;

while(x == 0){

Serial.println("Enter values for servos until both are stationary");
delay(100);

Serial.println("Enter value for left servo");
while (!Serial.available()) {;}
left = Serial.parseInt();
Serial.println(left);
delay(100);

Serial.println("Enter value for right servo");
while (!Serial.available()) {;}
right = Serial.parseInt();
Serial.println(right);
delay(100);

srvR.write(right);
srvL.write(left);

Serial.println("have both servos stopped?");
Serial.println("1 = Yes | 2 = No"); 

int j;
while (!Serial.available()) {;}
j = Serial.parseInt();

if (j == 1) {
  Serial.println("Saving calibration");
  EEPROM.write(leftMid, left);
  EEPROM.write(rightMid, right);
  srvConOn == false; 
  x == 1;
  } else if (j == 2) {
    Serial.println("Try again");
    Serial.println();
    }

} }

I'm working on a project for a robot and I'm trying to make a menu that can run on start up where the user can calibrate the mid-point for the servos (so they're stationary) and the ldrs so it can tell between black lines and white paper. So, I've made the menu a switch case where it calls the calibration when user enters a value, the calibration routines are their own functions. 

What I want to know how to do is how to make it so when the user is finished with a calibrator it will go back to the menu function and also how to get the menu to exit on user input. So far when the menu calls a function it will just loop on it.

The menu:

void Menu(){
  
  Serial.println("|****************************|");
  Serial.println("|**|Ardnoid Configuration |**|");
  Serial.println("|**|        Menu          |**|");
  Serial.println("|****************************|");
  Serial.println("");
  Serial.println("Select one of the following options:");
  Serial.println("1 LDR configuration");
  Serial.println("2 Servo calibration");
  Serial.println("3 Exit configuration menu");

  while(!Serial.available()){}
  int i = Serial.parseInt();

  switch(i){

  case 1:
    break;
  case 2:
    while(srvConOn == true){
      srvConfig();
      }
    break;strong text
  case 3:
    Serial.println("Leaving configuration menu"); 
    break;
  default:
    Serial.println("Unrecognized command, try again!");
    } 
 }

and the servo calibration:

void srvConfig(){

Serial.println("");
Serial.println("Begin servo stop calibration routine");

int x = 0;

  while(x == 0){
    
    Serial.println("Enter values for servos until both are stationary");
    delay(100);

    Serial.println("Enter value for left servo");
    while (!Serial.available()) {;}
    left = Serial.parseInt();
    Serial.println(left);
    delay(100);

    Serial.println("Enter value for right servo");
    while (!Serial.available()) {;}
    right = Serial.parseInt();
    Serial.println(right);
    delay(100);

    srvR.write(right);
    srvL.write(left);

    Serial.println("have both servos stopped?");
    Serial.println("1 = Yes | 2 = No"); 

    int j;
    while (!Serial.available()) {;}
    j = Serial.parseInt();
    
    if (j == 1) {
      Serial.println("Saving calibration");
      EEPROM.write(leftMid, left);
      EEPROM.write(rightMid, right);
      srvConOn == false; 
      x == 1;
      } else if (j == 2) {
        Serial.println("Try again");
        Serial.println();
        }
  }
}
Source Link
ROff
  • 13
  • 1
  • 5

Making a menu through serial

I'm working on a project for a robot and I'm trying to make a menu that can run on start up where the user can calibrate the mid-point for the servos (so they're stationary) and the ldrs so it can tell between black lines and white paper. So, I've made the menu a switch case where it calls the calibration when user enters a value, the calibration routines are their own functions. What I want to know how to do is how to make it so when the user is finished with a calibrator it will go back to the menu function and also how to get the menu to exit on user input. So far when the menu calls a function it will just loop on it. the menu:

`void Menu(){

Serial.println("||"); Serial.println("||Ardnoid Configuration ||"); Serial.println("|| Menu ||"); Serial.println("||"); Serial.println(""); Serial.println("Select one of the following options:"); Serial.println("1 LDR configuration"); Serial.println("2 Servo calibration"); Serial.println("3 Exit configuration menu");

while(!Serial.available()){} int i = Serial.parseInt();

switch(i){

case 1: break; case 2: while(srvConOn == true){ srvConfig(); } break;strong text case 3: Serial.println("Leaving configuration menu"); break; default: Serial.println("Unrecognized command, try again!"); } }`

and the servo calibration:

void srvConfig(){

Serial.println(""); Serial.println("Begin servo stop calibration routine");

int x = 0;

while(x == 0){

Serial.println("Enter values for servos until both are stationary");
delay(100);

Serial.println("Enter value for left servo");
while (!Serial.available()) {;}
left = Serial.parseInt();
Serial.println(left);
delay(100);

Serial.println("Enter value for right servo");
while (!Serial.available()) {;}
right = Serial.parseInt();
Serial.println(right);
delay(100);

srvR.write(right);
srvL.write(left);

Serial.println("have both servos stopped?");
Serial.println("1 = Yes | 2 = No"); 

int j;
while (!Serial.available()) {;}
j = Serial.parseInt();

if (j == 1) {
  Serial.println("Saving calibration");
  EEPROM.write(leftMid, left);
  EEPROM.write(rightMid, right);
  srvConOn == false; 
  x == 1;
  } else if (j == 2) {
    Serial.println("Try again");
    Serial.println();
    }

} }