Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SimpleModbusSlave.h>
- #define LED 9
- #define LUZ 13
- enum
- {
- ADC_VAL,
- LUZ_VAL,
- XPTO_VAL,
- HOLDING_REGS_SIZE // leave this one
- };
- unsigned int holdingRegs[HOLDING_REGS_SIZE]; // function 3 and 16 register array
- void setup()
- {
- modbus_configure(&Serial, 9600, SERIAL_8N2, 1, 2, HOLDING_REGS_SIZE, holdingRegs);
- modbus_update_comms(9600, SERIAL_8N2, 2);
- pinMode(LED, OUTPUT);
- pinMode(LUZ, INPUT_PULLUP);
- }
- void loop()
- {
- modbus_update();
- holdingRegs[ADC_VAL] = analogRead(A0); // update data to be read by the master to adjust the PWM
- holdingRegs[LUZ_VAL] = digitalRead(13); // update data to be read by the master to adjust the PWM
- // holdingRegs[LUZ_VAL] = analogRead(A1); // update data to be read by the master to adjust the PWM
- holdingRegs[XPTO_VAL] = 0x0228; // update data to be read by the master to adjust the PWM
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement