2023-01-31 09:22:55 +00:00
|
|
|
#include <Adafruit_ADS1X15.h> // https://github.com/adafruit/Adafruit_ADS1X15
|
2023-01-31 09:22:12 +00:00
|
|
|
|
|
|
|
#define WAIT_TIME 1000UL // default wait time each value read
|
|
|
|
#define ADS_MAX 4 // # of analog input pins of an ADS1115
|
|
|
|
#define VOLTAGE_RANGE 6.144f // ADS1115 default gain (+/- 6.144V)
|
|
|
|
#define CONST_I2C 32768 // a constant value
|
|
|
|
|
|
|
|
unsigned long currTime; // non-blocking timer
|
|
|
|
Adafruit_ADS1115 adc;
|
|
|
|
int i; // loop iterators
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
Wire.begin();
|
|
|
|
Serial.begin(19200);
|
|
|
|
adc.begin();
|
|
|
|
currTime = millis();
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
// TODO: The current reading is too slow for even the arduino's own ide's grapher cannot parse the data in time
|
|
|
|
if (millis() - currTime >= WAIT_TIME) { // non-blocking time delay
|
2023-01-31 10:18:13 +00:00
|
|
|
for (i = 0; i < ADS_MAX; i++) {
|
|
|
|
adcReadings[i] = adc.readADC_SingleEnded(i) * VOLTAGE_RANGE / CONST_I2C;
|
2023-01-31 09:22:12 +00:00
|
|
|
}
|
2023-01-31 10:18:13 +00:00
|
|
|
Serial.print("[");
|
|
|
|
for (i = 0; i < ADS_MAX; i++) {
|
|
|
|
Serial.print(adcReadings[i]);
|
|
|
|
if (i != ADS_MAX - 1) {
|
|
|
|
Serial.print(", ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Serial.println("]");
|
|
|
|
currTime = millis();
|
2023-01-31 09:22:12 +00:00
|
|
|
}
|
2023-01-31 09:22:55 +00:00
|
|
|
}
|