summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWolfgang (Wolle) Ewald <wolfgang.ewald@wolles-elektronikkiste.de>2020-08-04 18:56:52 +0200
committerGitHub <noreply@github.com>2020-08-04 18:56:52 +0200
commit43401e0461c7c3073cc57ec6050d2cae5ab4299f (patch)
tree8b5d3c8c4bd01d59563b6e7d976ca26dbbdfc5fe
parentUpdate ADS1115_WE.h (diff)
downloadADS1115_WE-43401e0461c7c3073cc57ec6050d2cae5ab4299f.tar
ADS1115_WE-43401e0461c7c3073cc57ec6050d2cae5ab4299f.tar.gz
ADS1115_WE-43401e0461c7c3073cc57ec6050d2cae5ab4299f.tar.bz2
ADS1115_WE-43401e0461c7c3073cc57ec6050d2cae5ab4299f.tar.lz
ADS1115_WE-43401e0461c7c3073cc57ec6050d2cae5ab4299f.tar.xz
ADS1115_WE-43401e0461c7c3073cc57ec6050d2cae5ab4299f.tar.zst
ADS1115_WE-43401e0461c7c3073cc57ec6050d2cae5ab4299f.zip
Diffstat (limited to '')
-rw-r--r--src/ADS1115_WE.cpp9
-rw-r--r--src/ADS1115_WE.h24
2 files changed, 21 insertions, 12 deletions
diff --git a/src/ADS1115_WE.cpp b/src/ADS1115_WE.cpp
index e3df817..9da6d48 100644
--- a/src/ADS1115_WE.cpp
+++ b/src/ADS1115_WE.cpp
@@ -163,6 +163,15 @@ float ADS1115_WE::getResult_mV(){
return result;
}
+int16_t ADS1115_WE::getResultWithRange(int16_t min, int16_t max){
+ int16_t rawResult = readRegister(ADS1115_CONV_REG);
+ //rawResult = (int) (rawResult * (voltageRange * 1.0 / 6144));
+ int16_t result = 0;
+ result = map(rawResult, 0, 32767, min, max);
+ return result;
+}
+
+
void ADS1115_WE::setAlertPinToConversionReady(){
writeRegister(ADS1115_LO_THRESH_REG, (0<<15));
writeRegister(ADS1115_HI_THRESH_REG, (1<<15));
diff --git a/src/ADS1115_WE.h b/src/ADS1115_WE.h
index 115d4bd..ce0cec2 100644
--- a/src/ADS1115_WE.h
+++ b/src/ADS1115_WE.h
@@ -27,10 +27,10 @@
#include <Wire.h>
/* registers */
-#define ADS1115_CONV_REG 0x00 //Conversion Register
-#define ADS1115_CONFIG_REG 0x01 //Configuration Register
-#define ADS1115_LO_THRESH_REG 0x02 //Low Threshold Register
-#define ADS1115_HI_THRESH_REG 0x03 //High Threshold Register
+#define ADS1115_CONV_REG 0x00 //Conversion Register
+#define ADS1115_CONFIG_REG 0x01 //Configuration Register
+#define ADS1115_LO_THRESH_REG 0x02 //Low Threshold Register
+#define ADS1115_HI_THRESH_REG 0x03 //High Threshold Register
/* other */
#define ADS1115_REG_FACTOR 32768
@@ -76,12 +76,12 @@ typedef enum ADS1115_MEASURE_MODE{
} measureMode;
typedef enum ADS1115_RANGE{
- ADS1115_RANGE_6144 = 0x0000,
- ADS1115_RANGE_4096 = 0x0200,
+ ADS1115_RANGE_6144 = 0x0000,
+ ADS1115_RANGE_4096 = 0x0200,
ADS1115_RANGE_2048 = 0x0400,
- ADS1115_RANGE_1024 = 0x0600,
- ADS1115_RANGE_0512 = 0x0800,
- ADS1115_RANGE_0256 = 0x0A00,
+ ADS1115_RANGE_1024 = 0x0600,
+ ADS1115_RANGE_0512 = 0x0800,
+ ADS1115_RANGE_0256 = 0x0A00,
} range;
typedef enum ADS1115_MUX{
@@ -96,7 +96,7 @@ typedef enum ADS1115_MUX{
} mux;
typedef enum ADS1115_STATUS_OR_START{
- ADS1115_BUSY = 0x0000,
+ ADS1115_BUSY = 0x0000,
ADS1115_START_ISREADY = 0x8000
} statusOrStart;
@@ -202,10 +202,10 @@ public:
void startSingleMeasurement();
float getResult_V();
float getResult_mV();
+ int16_t getResultWithRange(int16_t min, int16_t max);
/* With this function the alert pin will be active, when a conversion is ready.
- * In order to deactivate the conversion ready alert, use
- * setAlertPinMode(ADS1115_DISABLE_ALERT) or setAlertModeAndLimit_V()
+ * In order to deactivate, use the setAlertLimit_V function
*/
void setAlertPinToConversionReady();
void clearAlert();