mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
68 lines
1.4 KiB
C++
68 lines
1.4 KiB
C++
//
|
|
// FILE: ADS_setWireClock.ino
|
|
// AUTHOR: Rob.Tillaart
|
|
// VERSION: 0.1.0
|
|
// 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();
|
|
|
|
Serial.println(F("\nSET\tACTUAL\n=================="));
|
|
for (uint32_t speed = 50000; speed <= 1000000; speed += 50000)
|
|
{
|
|
ADS.setWireClock(speed);
|
|
Serial.print(speed);
|
|
Serial.print("\t");
|
|
Serial.println(ADS.getWireClock());
|
|
}
|
|
ADS.setWireClock(100000);
|
|
Serial.println();
|
|
}
|
|
|
|
|
|
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 --
|
|
|