analog card
This commit is contained in:
parent
1f8ad10609
commit
51e9f5258a
|
@ -1,30 +1,44 @@
|
||||||
#include <ESPMegaPRO.h>
|
#include <ESPMegaPRO.h>
|
||||||
#include <AnalogCard.hpp>
|
#include <AnalogCard.hpp>
|
||||||
|
|
||||||
void AnalogCard::dacWrite(uint8_t pin, uint16_t value) {
|
AnalogCard::AnalogCard() : dac0(DAC0_ADDRESS),
|
||||||
switch(pin) {
|
dac1(DAC1_ADDRESS),
|
||||||
case 0:
|
dac2(DAC2_ADDRESS),
|
||||||
this->dac0.writeDAC(value);
|
dac3(DAC3_ADDRESS)
|
||||||
break;
|
{
|
||||||
case 1:
|
}
|
||||||
this->dac1.writeDAC(value);
|
|
||||||
break;
|
void AnalogCard::dacWrite(uint8_t pin, uint16_t value)
|
||||||
case 2:
|
{
|
||||||
this->dac2.writeDAC(value);
|
switch (pin)
|
||||||
break;
|
{
|
||||||
case 3:
|
case 0:
|
||||||
this->dac3.writeDAC(value);
|
this->dac0.writeDAC(value);
|
||||||
break;
|
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) {
|
uint16_t AnalogCard::analogRead(uint8_t pin)
|
||||||
if (pin >= 0 && pin <= 3) {
|
{
|
||||||
|
if (pin >= 0 && pin <= 3)
|
||||||
|
{
|
||||||
return this->analogInputBankA.readADC_SingleEnded(pin);
|
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);
|
return this->analogInputBankB.readADC_SingleEnded(pin - 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void AnalogCard::begin() {
|
void AnalogCard::begin()
|
||||||
|
{
|
||||||
this->dac0 = MCP4725(DAC0_ADDRESS);
|
this->dac0 = MCP4725(DAC0_ADDRESS);
|
||||||
this->dac1 = MCP4725(DAC1_ADDRESS);
|
this->dac1 = MCP4725(DAC1_ADDRESS);
|
||||||
this->dac2 = MCP4725(DAC2_ADDRESS);
|
this->dac2 = MCP4725(DAC2_ADDRESS);
|
||||||
|
|
|
@ -1,19 +1,38 @@
|
||||||
#include <ESPMegaPRO.h>
|
#include <ESPMegaPRO.h>
|
||||||
#include <DigitalInputCard.hpp>
|
#include <DigitalInputCard.hpp>
|
||||||
#include <DigitalOutputCard.hpp>
|
#include <DigitalOutputCard.hpp>
|
||||||
|
#include <AnalogCard.hpp>
|
||||||
|
|
||||||
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() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
// Instantiate Input Card
|
// Instantiate Input Card
|
||||||
icard.begin();
|
icard.begin();
|
||||||
|
// Instantiate Output Card
|
||||||
|
ocard.begin();
|
||||||
|
// Instantiate Analog Card
|
||||||
|
acard.begin();
|
||||||
|
// Set output 0 to 4095
|
||||||
|
ocard.analogWrite(0, 4095);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// put your main code here, to run repeatedly:
|
// put your main code here, to run repeatedly:
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
|
Serial.print("Input ");
|
||||||
|
Serial.print(i);
|
||||||
|
Serial.print(": ");
|
||||||
Serial.print(icard.digitalRead(i));
|
Serial.print(icard.digitalRead(i));
|
||||||
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
// Pad the output
|
||||||
|
Serial.println();
|
||||||
|
Serial.println();
|
||||||
|
// Delay for 1 second
|
||||||
|
delay(1000);
|
||||||
}
|
}
|
Loading…
Reference in New Issue