// basic master arduino, should transmit a switch value to open and close a servo on the slave,
// as well as receive a pressure value from the slave - need to setup analogue pressure to psi equation
#include <SimpleModbusMaster.h>
#include <Wire.h> // Include the Wire library for I2C communication
#include <LiquidCrystal_I2C.h> // Include the library for I2C LCD
LiquidCrystal_I2C lcd(0x27, 16, 2); // Initialize LCD with I2C address 0x27, and 16 columns and 2 rows
#define baud 9600
#define timeout 1000
#define polling 200
#define retry_count 5
#define TxEnablePin 2
#define buttonPin 5
enum
{
PACKET1,
PACKET2,
TOTAL_NO_OF_PACKETS
};
Packet packets[TOTAL_NO_OF_PACKETS];
packetPointer packet1 = &packets[PACKET1];
packetPointer packet2 = &packets[PACKET2];
unsigned int writeRegs[4];
unsigned int readRegs[2];
void setup()
{
modbus_construct(packet1, 1, READ_HOLDING_REGISTERS, 0, 2, readRegs);
modbus_construct(packet2, 1, PRESET_MULTIPLE_REGISTERS, 2, 4, writeRegs);
modbus_configure(baud, SERIAL_8N2, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS);
pinMode(LED, OUTPUT);
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
pinMode(buttonPin, INPUT);
}
void loop()
{
modbus_update();
writeRegs[2] = digitalRead(buttonPin);
lcd.print(readRegs[0]/2)
}