Software_and_hardware/sketch_feb14a/sketch_feb14a.ino

20 lines
772 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <SimpleModbusSlave.h>
#define PIN1 7 // Контролируемый пин
// Настройка регистров
#define TOTAL_REGS 1
uint16_t regs[TOTAL_REGS] = {0}; // Один регистр для хранения состояния пина
SimpleModbusSlave slave(1); // Инициализация устройства с ID 1
void setup() {
pinMode(PIN1, INPUT); // Настроим пин как вход
slave.setup(115200); // Установим скорость передачи данных 115200 бод
}
void loop() {
regs[0] = digitalRead(PIN1); // Читаем состояние пина и записываем в регистр
slave.loop(regs, TOTAL_REGS); // Обрабатываем Modbus-запросы
}