ModBus RS485 addressing problems?

Good morning, I came across a video by Paolo Aliverti for the RS485 transmission ModBus protocol with data exchange between Master and Slave, I liked it and I would like to deepen it so I replied everything is working, then I thought why not add another button and another led?
And here the donkey falls …
i tried and tried again nothing done did any of you work with the modbus protocol?
I would like to understand how to send data on the one hand and interpret it on the other I insert the Master and slave sketches for concrete help.

Thank you all.

Master

#include <ModbusMaster.h>
#include <SoftwareSerial.h>
SoftwareSerial RS485Serial(10, 11); // RX, TX
#define MAX485_DE_RE    2

ModbusMaster node;

void preTransmission() {
  digitalWrite(MAX485_DE_RE, HIGH);
}
void postTransmission() {
  digitalWrite(MAX485_DE_RE, LOW);
}

#define led1  5 // led 1
#define led2 8  // led 2

void setup() {
  pinMode (led1, OUTPUT);
  pinMode (led2, OUTPUT);
  digitalWrite (led1, HIGH);
  digitalWrite (led2, HIGH);


  pinMode(MAX485_DE_RE, OUTPUT);
  digitalWrite(MAX485_DE_RE, LOW);
  //Serial.begin(9600);
  RS485Serial.begin(9600);

  node.begin(1, RS485Serial);
  node.preTransmission(preTransmission);
  node.postTransmission(postTransmission);

}

int led = LOW;
int ret = 0;

void loop() {

  ret = node.readDiscreteInputs(0x0005, 16); // 0x0005 indirizzo 5

  if (ret == node.ku8MBSuccess) {
    unsigned int ret = node.getResponseBuffer(0x0000); // 16 posizioni es:0000 0000 0000 0001

    if (ret = node.getResponseBuffer(0x0000) == LOW)
    {
      digitalWrite(5, HIGH);
    }
    else
    {
      digitalWrite(5, LOW);
    }

    ret = node.writeSingleCoil(0x000C, led);
    led = !led;
    delay(1000);
  }
  if (ret = node.getResponseBuffer(0x0001) == LOW)
  {
    digitalWrite(8, HIGH);
  }
  else
  {
    digitalWrite(8, LOW);
  }

}

Slave

#include <SoftwareSerial.h>
#include <ModbusSlave.h>

SoftwareSerial RS485Serial(10, 11); // RX, TX
Modbus slave(RS485Serial, 1, 2 );

#define tasto1 5  //pin 5
#define tasto2 6 //pin 6
#define ledstato 12 //pin 12

void setup() {

  pinMode(2, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(5, INPUT);
  pinMode(6, INPUT);

  slave.cbVector[CB_WRITE_COILS] = writeDigitalOut;
  slave.cbVector[CB_READ_COILS] = readDigital;
  slave.cbVector[CB_READ_DISCRETE_INPUTS] = readDigital;

  Serial.begin(9600);
  RS485Serial.begin(9600);
  slave.begin(9600);
}

void loop() {
  slave.poll();
}
uint8_t writeDigitalOut(uint8_t fc, uint16_t address, uint16_t length) {
  Serial.print("FC=05: ");
  Serial.println(fc);
  Serial.println(address);
  Serial.println(length);

  if (address == 12) {
    digitalWrite(12, slave.readCoilFromBuffer(0x00)); // ritorno master

  }
  return STATUS_OK;
}
uint8_t readDigital(uint8_t fc, uint16_t address, uint16_t length) {
  Serial.print("FC=01/02: ");
  Serial.println(fc); // tipo di classe
  Serial.println(address);// indirizzo da leggere
  Serial.println(length); // n. bit

  for (int i = 0; i < length; i++) {
    int bt = 0;
    if (i == 0) {
      bt = digitalRead(5);
    }
    slave.writeCoilToBuffer(i, bt); //invio master
  }

  for (int i = 0; i < length; i++) {
    int bt = 0;
    if (i == 0) {
      bt = digitalRead(6);
    }
    slave.writeCoilToBuffer(i, bt); //invio master
  }
  return STATUS_OK;
}

can you explain how your code works?
i'm not familiar with modbus and confused by writeCoilToBuffer() (what's a coil)?

looks like cbVector specifies callback functions. are CB_READ_COIL and CR_READ_DISCRETE_COIL similar and readDigital() is appropriate for both and suggests two separate inputs, but readDigital() seems to be read two separate inputs.

should each call to readDigital() queue two or only one meassge?

gcjr:
can you explain how your code works?
i'm not familiar with modbus and confused by writeCoilToBuffer() (what's a coil)?

looks like cbVector specifies callback functions. are CB_READ_COIL and CR_READ_DISCRETE_COIL similar and readDigital() is appropriate for both and suggests two separate inputs, but readDigital() seems to be read two separate inputs.

should each call to readDigital() queue two or only one meassge?

I don't have much experience it is the ModBus protocol, the idea came by watching a video on youtubelink:Lettura di un contatto o di coil con sistema modbus master-slave realizzato con Arduino - Video 317 - YouTube

Therefore I ran into this problem by replicating the commands I realized that we must work on buffer input but I did not understand how, that's why I asked for help here in the forum.