Blame | Last modification | View Log | Download
/*Modbus-Arduino Example - Lamp (Modbus IP)Copyright by André Sarmento Barbosahttp://github.com/andresarmento/modbus-arduino*/#include <SPI.h>#include <Ethernet.h>#include <Modbus.h>#include <ModbusIP.h>//Modbus Registers Offsets (0-9999)const int LAMP1_COIL = 100;//Used Pinsconst int ledPin = 9;//ModbusIP objectModbusIP mb;void setup() {// The media access control (ethernet hardware) address for the shieldbyte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };// The IP address for the shieldbyte ip[] = { 192, 168, 1, 120 };//Config Modbus IPmb.config(mac, ip);//Set ledPin modepinMode(ledPin, OUTPUT);// Add LAMP1_COIL register - Use addCoil() for digital outputsmb.addCoil(LAMP1_COIL);}void loop() {//Call once inside loop() - all magic heremb.task();//Attach ledPin to LAMP1_COIL registerdigitalWrite(ledPin, mb.Coil(LAMP1_COIL));}