Communication between 2 arduino programs (menu - main)

Hey, I've designed a program to convert special format trames from an underwater acoustic positionning system to a AIS format trames which are readable on any Navigation system. I've got the soft part working fine, now I am beginning the hardware part which is composed by an 16*4 LCD screen and interrupts.
I would like to create an interface menu where I can choose the properties of my serial communication for the AIS trame. Is it possible to create two different program and linked them to assign some variable from my menu program to the main ?

Eg, my interface program which I've juste started :

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 4);
  // Print a welcome message to the LCD.
  lcd.print("Welcome on the USBL box from JIFMAR !");
  delay(5000);
  lcd.clear();
}

void loop() {
  lcd.setCursor(8, 0);
  lcd.print("MENU");
  lcd.setCursor(0, 1);
  lcd.print( "1: Target definition");
  lcd.setCursor(0, 2);
  lcd.print( "2: Serial ports ");
  lcd.setCursor(0, 3);
  lcd.print( "3: Start");
}

Once I am in the "Serial ports" menu I would like to set a variable Baudrate1 for exemple that I would use for the setup of my main pg:

void setup() {
  Serial1.begin(Baudrate1);                   //on initialise les ports series
  Serial2.begin(4800);
  Serial3.begin(19200);
  for (j=0;j<200;j++) {                  //RAZ du buffer de ligne
      line[j] = ' ';
  }
}

Thanks if you have any ideas, I would like to avoid to make longer my main which is already quite long :slight_smile:

Vince

now I am beginning the hardware part which is composed by an 16*4 LCD screen and interrupts.

Interrupts are not hardware. They are software.

Once I am in the "Serial ports" menu I would like to set a variable Baudrate1 for exemple that I would use for the setup of my main

You don't (appear to) have a "Serial ports" menu. You have a "2: Serial ports" text displayed on the LCD. Since you do that in loop(), which is run AFTER setup(), it hardly seems likely that you will be able to set the value of a variable that will be used in setup().

Of course, Serial.begin() doesn't HAVE to be called in setup(). It can be called any time you know the baud rate to use. Or, call it with a default value in setup(), and then call Serial.end() and Serial.begin() with a new value, when you have a new value.

JifVince:
Is it possible to create two different program and linked them to assign some variable from my menu program to the main ?

You can't have two different programs in one Arduino but you can have several different functions which could be selected by a menu.

...R

now I am beginning the hardware part which is composed by an 16*4 LCD screen and interrupts.

Interrupts are not hardware. They are software.

Sorry I mean switches, my mix of french and english makes it hard :slight_smile:

Ah ok, I thought the Serial.begin would have be defined in the setup function,

The think is my program is very long so I would like to separate them since I use the menu to set various parameter, and once these parameters are set the program is always running. Yes ok I will include the menu into the main program and find a way to jump between these 2.

Thank for your help.

Vince