diff --git a/Template Project/lib/ESPMegaPRO/AnalogCard.cpp b/Template Project/lib/ESPMegaPRO/AnalogCard.cpp index a053484..e7bf577 100644 --- a/Template Project/lib/ESPMegaPRO/AnalogCard.cpp +++ b/Template Project/lib/ESPMegaPRO/AnalogCard.cpp @@ -1,30 +1,44 @@ #include #include -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; +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; } } -uint16_t AnalogCard::analogRead(uint8_t pin) { - if (pin >= 0 && pin <= 3) { +uint16_t AnalogCard::analogRead(uint8_t pin) +{ + if (pin >= 0 && pin <= 3) + { return this->analogInputBankA.readADC_SingleEnded(pin); - } else if (pin >= 4 && pin <= 7) { + } + else if (pin >= 4 && pin <= 7) + { return this->analogInputBankB.readADC_SingleEnded(pin - 4); } } -void AnalogCard::begin() { +void AnalogCard::begin() +{ this->dac0 = MCP4725(DAC0_ADDRESS); this->dac1 = MCP4725(DAC1_ADDRESS); this->dac2 = MCP4725(DAC2_ADDRESS); diff --git a/Template Project/src/cardsdemo.cpp b/Template Project/src/cardsdemo.cpp index c7bc690..f0c1ca5 100644 --- a/Template Project/src/cardsdemo.cpp +++ b/Template Project/src/cardsdemo.cpp @@ -1,19 +1,38 @@ #include #include #include +#include -DigitalInputCard icard = DigitalInputCard(0x20, 0x21); +// This code demonstrates how to use the cards +DigitalInputCard icard = DigitalInputCard(0x21, 0x22); +DigitalOutputCard ocard = DigitalOutputCard(0x5F); +AnalogCard acard = AnalogCard(); void setup() { Serial.begin(115200); // Instantiate Input Card icard.begin(); + // Instantiate Output Card + ocard.begin(); + // Instantiate Analog Card + acard.begin(); + // Set output 0 to 4095 + ocard.analogWrite(0, 4095); } void loop() { // put your main code here, to run repeatedly: for (int i = 0; i < 16; i++) { + Serial.print("Input "); + Serial.print(i); + Serial.print(": "); Serial.print(icard.digitalRead(i)); + Serial.println(); } + // Pad the output + Serial.println(); + Serial.println(); + // Delay for 1 second + delay(1000); } \ No newline at end of file