ESPMegaPRO-v3-SDK/Template Project/lib/ESPMegaPRO/AnalogCard.cpp

51 lines
1.2 KiB
C++
Raw Normal View History

2023-12-27 16:15:11 +00:00
#include <AnalogCard.hpp>
2023-12-27 16:41:58 +00:00
AnalogCard::AnalogCard() : dac0(DAC0_ADDRESS),
dac1(DAC1_ADDRESS),
dac2(DAC2_ADDRESS),
dac3(DAC3_ADDRESS)
{
}
void AnalogCard::dacWrite(uint8_t pin, uint16_t value)
{
switch (pin)
{
case 0:
this->dac0.writeDAC(value);
break;
case 1:
this->dac1.writeDAC(value);
break;
case 2:
this->dac2.writeDAC(value);
break;
case 3:
this->dac3.writeDAC(value);
break;
2023-12-27 16:15:11 +00:00
}
}
2023-12-27 16:41:58 +00:00
uint16_t AnalogCard::analogRead(uint8_t pin)
{
if (pin >= 0 && pin <= 3)
{
2023-12-27 16:15:11 +00:00
return this->analogInputBankA.readADC_SingleEnded(pin);
2023-12-27 16:41:58 +00:00
}
else if (pin >= 4 && pin <= 7)
{
2023-12-27 16:15:11 +00:00
return this->analogInputBankB.readADC_SingleEnded(pin - 4);
}
}
2023-12-27 16:41:58 +00:00
void AnalogCard::begin()
{
2023-12-27 16:15:11 +00:00
this->dac0 = MCP4725(DAC0_ADDRESS);
this->dac1 = MCP4725(DAC1_ADDRESS);
this->dac2 = MCP4725(DAC2_ADDRESS);
this->dac3 = MCP4725(DAC3_ADDRESS);
this->dac0.begin();
this->dac1.begin();
this->dac2.begin();
this->dac3.begin();
this->analogInputBankA.begin(ANALOG_INPUT_BANK_A_ADDRESS);
this->analogInputBankB.begin(ANALOG_INPUT_BANK_B_ADDRESS);
}