#include AnalogCard::AnalogCard() : dac0(DAC0_ADDRESS), dac1(DAC1_ADDRESS), dac2(DAC2_ADDRESS), dac3(DAC3_ADDRESS), analogInputBankA(), analogInputBankB() { } 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; } } uint16_t AnalogCard::analogRead(uint8_t pin) { if (pin >= 0 && pin <= 3) { return this->analogInputBankA.readADC_SingleEnded(pin); } else if (pin >= 4 && pin <= 7) { return this->analogInputBankB.readADC_SingleEnded(pin - 4); } return 65535; } bool AnalogCard::begin() { this->dac0 = MCP4725(DAC0_ADDRESS); this->dac1 = MCP4725(DAC1_ADDRESS); this->dac2 = MCP4725(DAC2_ADDRESS); this->dac3 = MCP4725(DAC3_ADDRESS); if (!this->dac0.begin()) { Serial.println("Card Analog ERROR: Failed to install DAC0"); return false; } if (!this->dac1.begin()) { Serial.println("Card Analog ERROR: Failed to install DAC1"); return false; } if (!this->dac2.begin()) { Serial.println("Card Analog ERROR: Failed to install DAC2"); return false; } if (!this->dac3.begin()) { Serial.println("Card Analog ERROR: Failed to install DAC3"); return false; } if (!this->analogInputBankA.begin()) { Serial.println("Card Analog ERROR: Failed to install analog input bank A"); return false; } if (!this->analogInputBankB.begin()) { Serial.println("Card Analog ERROR: Failed to install analog input bank B"); return false; } return true; } void AnalogCard::loop() { } uint8_t AnalogCard::getType() { return CARD_TYPE_ANALOG; }