You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
IFB_dev/FC_InterfaceBoard/Analog_Out.ino

80 lines
1.5 KiB
C++

void AO_setup(int i, int Rng) {
DFRobot_GP8403* AO;
bool needBegin = true;
bool needRng = true;
needBegin = (RngAO[i] == 0);
if(i <= 1){
AO = &AO_0;
}else if(i <= 3){
AO = &AO_2;
}else if(i <= 5){
AO = &AO_4;
}else if(i <= 7){
AO = &AO_6;
}else if(i <= 9){
AO = &AO_8;
}else if(i <= 11){
AO = &AO_10;
}else if(i <= 13){
AO = &AO_12;
}else if(i <= 15){
AO = &AO_14;
}
if(needBegin){ // If not begin yet
Serial.println("AO_"+ String(i) + ": initialization Begin");
while(AO->begin()!=0);
AO->setDACOutVoltage(0, 2);
delay(5);
AO->store();
}
if(Rng == 10){
AO->setDACOutRange(AO->eOutputRange10V);
Serial.println("AO_"+ String(i) + ": Initialized, Set Range 10V");
}else{
AO->setDACOutRange(AO->eOutputRange5V);
Serial.println("AO_"+ String(i) + ": Initialized, Set Range 5V");
}
RngAO[i] = Rng;
RngAO[i+1] = Rng;
}
void AO_Write(int i, int volt) {
DFRobot_GP8403* AO;
int ch;
if(i%2){ // Odd
ch = 1;
}else{ // Even
ch = 0;
}
if(i <= 1){
AO = &AO_0;
}else if(i <= 3){
AO = &AO_2;
}else if(i <= 5){
AO = &AO_4;
}else if(i <= 7){
AO = &AO_6;
}else if(i <= 9){
AO = &AO_8;
}else if(i <= 11){
AO = &AO_10;
}else if(i <= 13){
AO = &AO_12;
}else if(i <= 15){
AO = &AO_14;
}
Serial.println(" [AO] " + String(i) + " > " + String(volt));
//Serial.print(" > ");
//Serial.println(volt);
AO->setDACOutVoltage(volt, ch);
}