buttons/actions question

Let us convert your BASIC Program into a Flow Chart to visualize the course of actions to be taken when some excitation are applied from outside by pressing the buttons. After that we will see the ways that we follow to grasp the meanings of the Flow Chart using a sketch in the Arduino IDE using Arduino macros and C Programming Language Elements (the constructs).

A: hardware Block Diagram for the System

Figure-1: Block diagram showing a tentative connections among Buttons, Relays, and PC

B: Flow Chart for the Control program of Fig-1

Figure-2: Flow Chart for the user Control Program

Program Codes

void setup()
{
  Serial.begin(9600);

  pinMode(2, INPUT_PULLUP);  //DPin-2 is input line with internal pull-up connected
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);

  pinMode(8, OUTPUT);     //direction of DPin-8 is outgoing
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);

  digitalWrite(8, LOW);    //DPin-8 is at Logic Low
  digitalWrite(9, LOW);
  digitalWrite(10, LOW);
}

void loop()
{
  if (digitalRead(2) != HIGH)  //checking if Button1 has been closed
  {
    relay1Control();    //equivalent to GOSUB10
  }

  if (digitalRead(3) != HIGH) //checking if Button2 has been closed
  {
    relay2Control();    //equivalent to GOSUB20
  }

  if (digitalRead(4) != HIGH) //checking if button3 has been closed
  {
    relay3Control();    //equivalent to GOSUB30
  }
}

void relay1Control()
{
  //activate Relay1 (RL1)
  digitalWrite(8, HIGH);

  //retuen to Main Line Program (MLP)
}

void relay2Control()
{
  //activate Relay1 (RL2)
  digitalWrite(9, HIGH);

  //retuen to Main Line Program (MLP)
}

void relay3Control()
{
  //activate Relay1 (RL3)
  digitalWrite(10, HIGH);

  //retuen to Main Line Program (MLP)
}