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_InferfaceBoard/Analog_Out.ino

90 lines
1.5 KiB
C++

void AO_setup(int i, int Rng) {
DFRobot_GP8403 AO;
bool needBegin = true;
bool needRng = true;
int twinRng = 0;
if(i%2){ // Odd
twinRng = RngAO[i-1];
}else{ // Even
twinRng = RngAO[i+1];
}
needBegin = (twinRng == 0);
if(Rng > twinRng){
needRng = true;
}else{
needRng = false;
}
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 init begin");
while(AO.begin()!=0);
Serial.println("AO init succeed");
AO.setDACOutVoltage(0, 0);
AO.setDACOutVoltage(0, 1);
delay(20);
AO.store();
}
if(needRng){
if(Rng == 10){
AO.setDACOutRange(AO.eOutputRange10V);
}else{
AO.setDACOutRange(AO.eOutputRange5V);
}
}
RngAO[i] = Rng;
Serial.println("AO FIN");
}
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;
}
AO.setDACOutVoltage(volt, ch);
}