Skip to content

Commit

Permalink
minor edit
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart committed Oct 19, 2024
1 parent 6cbd9f9 commit ae9b2fb
Showing 1 changed file with 26 additions and 35 deletions.
61 changes: 26 additions & 35 deletions examples/ADS_read_getError/ADS_read_getError.ino
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@

ADS1115 ADS(0x48);

int16_t value[4];
int err = ADS1X15_OK;
float voltageFactor = 1;

void setup()
void setup()
{
Serial.begin(115200);
Serial.println();
Expand All @@ -29,49 +32,37 @@ void setup()

Wire.begin();
ADS.begin();

voltageFactor = ADS.toVoltage(1);
}


void loop()
void loop()
{
ADS.setGain(0);

int16_t val_0 = ADS.readADC(0);
int err = ADS.getError();
if (err != ADS1X15_OK)
{
Serial.print("input 0 => ");
Serial.println(err);
}
int16_t val_1 = ADS.readADC(1);
err = ADS.getError();
if (err != ADS1X15_OK)
{
Serial.print("input 1 => ");
Serial.println(err);
}
int16_t val_2 = ADS.readADC(2);
err = ADS.getError();
if (err != ADS1X15_OK)
{
Serial.print("input 2 => ");
Serial.println(err);
}
int16_t val_3 = ADS.readADC(3);
err = ADS.getError();
if (err != ADS1X15_OK)
float f = ADS.toVoltage(1); // voltage factor

for (int channel = 0; channel < 4; channel++)
{
Serial.print("input 3 => ");
Serial.println(err);
}
value[channel] = ADS.readADC(channel);
err = ADS.getError();
if (err != ADS1X15_OK)
{
Serial.print(channel);
Serial.print(" returns error: ");
Serial.println(err);
}

float f = ADS.toVoltage(1); // voltage factor
Serial.print("\tChannel ");
Serial.print(channel);
Serial.print(": ");
Serial.print(value[channel]);
Serial.print('\t');
Serial.println(value[channel] * voltageFactor, 3);
}

Serial.print("\tAnalog0: "); Serial.print(val_0); Serial.print('\t'); Serial.println(val_0 * f, 3);
Serial.print("\tAnalog1: "); Serial.print(val_1); Serial.print('\t'); Serial.println(val_1 * f, 3);
Serial.print("\tAnalog2: "); Serial.print(val_2); Serial.print('\t'); Serial.println(val_2 * f, 3);
Serial.print("\tAnalog3: "); Serial.print(val_3); Serial.print('\t'); Serial.println(val_3 * f, 3);
Serial.println();
// optional do other things with value[channel]

delay(1000);
}
Expand Down

0 comments on commit ae9b2fb

Please sign in to comment.