4 #include <ArduinoLog.h>
12 #ifdef PLATFORM_PORTENTA_H7_M7
13 #include <Arduino_MachineControl.h>
14 using namespace machinecontrol;
15 float res_divider = 0.28057;
21 class POT :
public Component,
public ModbusValue<int>
29 short _addr) : ModbusValue<int>(_addr, MB_FC::MB_FC_READ_REGISTERS),
30 Component(
"POT", _id, Component::COMPONENT_DEFAULT, owner),
35 SBI(nFlags, OBJECT_NET_CAPS::E_NCAPS_MODBUS);
36 setRegisterMode(MB_REGISTER_MODE::E_MB_REGISTER_MODE_READ);
40 #ifdef PLATFORM_PORTENTA_H7_M7
41 analogReadResolution(16);
51 #ifdef PLATFORM_PORTENTA_H7_M7
52 Log.verbose(F(
"POT:debug pin=%d value=%d | %d" CR), pin, value, analog_in.read(pin));
58 short info(
short val0,
short val1)
60 Log.verboseln(
"POT::info - Pin=%d | Key=%d | Addr=%d | Val=%d | NetVal=%d ", pin,
id, addr, value, netVal());
70 #ifdef PLATFORM_PORTENTA_H7_M7
71 float raw_voltage_ch0 = analog_in.read(pin);
72 float voltage_ch0 = (raw_voltage_ch0 * reference) / 65535 / res_divider;
75 value = analogRead(pin);
83 bridge->registerMemberFunction(
id,
this, C_STR(
"setFlag"), (ComponentFnPtr)&POT::setFlag);
85 bridge->registerMemberFunction(
id,
this, C_STR(
"info"), (ComponentFnPtr)&
POT::info);