Thanks for your comments!
As you will watch, the Modbus library just needs a memory array to exchange data through the network. The difference between a Master and an Slave is that the Master sends queries and waits for answer, while the Slave waits for queries and sends answers. Your code shall fill or read this memory array.
In my previous example, this memory array was called au16data. This means than all you need is to modify the code available here and write something like this:
void setup() {
pinMode( 4, INPUT );
pinMode( 5, INPUT );
pinMode( 6, INPUT );
pinMode( 7, INPUT );
pinMode( 8, OUTPUT );
pinMode( 9, OUTPUT );
pinMode( 10, OUTPUT );
pinMode( 11, OUTPUT );
slave.begin(19200);
}
void loop() {
// inputs 4..7 shall be at au16data[0]
bitWrite( au16data[0], 0, digitalRead(4) );
bitWrite( au16data[0], 1, digitalRead(5) );
bitWrite( au16data[0], 2, digitalRead(6) );
bitWrite( au16data[0], 3, digitalRead(7) );
// outputs 8..11 shall be at au16data[1]
digitalWrite( 8, bitRead( au16data[1], 0 ));
digitalWrite( 9, bitRead( au16data[1], 1 ));
digitalWrite( 10, bitRead( au16data[1], 2 ));
digitalWrite( 11, bitRead( au16data[1], 3 ));
// analog inputs 0 and 1 at au16data[2] and au16data[3]
au16data[2] = analogRead(0);
au16data[3] = analogRead(1);
slave.poll( au16data, 17 );
}
I hope that this helps to answer your question.
Greetings!
/S