mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
57 lines
1.1 KiB
C++
57 lines
1.1 KiB
C++
//
|
|
// FILE: ADS_read.ino
|
|
// AUTHOR: Rob.Tillaart
|
|
// VERSION: 0.2.1
|
|
// PURPOSE: read analog inputs - straightforward.
|
|
//
|
|
|
|
// test
|
|
// connect 1 potmeter per port.
|
|
//
|
|
// GND ---[ x ]------ 5V
|
|
// |
|
|
//
|
|
// measure at x (connect to AIN0).
|
|
//
|
|
|
|
|
|
#include "ADS1X15.h"
|
|
|
|
ADS1115 ADS(0x48);
|
|
|
|
|
|
void setup()
|
|
{
|
|
Serial.begin(115200);
|
|
Serial.println(__FILE__);
|
|
Serial.print("ADS1X15_LIB_VERSION: ");
|
|
Serial.println(ADS1X15_LIB_VERSION);
|
|
|
|
ADS.begin();
|
|
}
|
|
|
|
|
|
void loop()
|
|
{
|
|
ADS.setGain(0);
|
|
|
|
int16_t val_0 = ADS.readADC(0);
|
|
int16_t val_1 = ADS.readADC(1);
|
|
int16_t val_2 = ADS.readADC(2);
|
|
int16_t val_3 = ADS.readADC(3);
|
|
|
|
float f = ADS.toVoltage(1); // voltage factor
|
|
|
|
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();
|
|
|
|
delay(1000);
|
|
}
|
|
|
|
|
|
// -- END OF FILE --
|
|
|