Skip to content

Commit ad26ad4

Browse files
committed
add setchannel
1 parent 890031c commit ad26ad4

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Adafruit_NAU7802.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,24 @@ bool Adafruit_NAU7802::available(void) {
147147
return conv_ready.read();
148148
}
149149

150+
/**************************************************************************/
151+
/*!
152+
@brief Set which channel for ADC
153+
@param channel Set to 0 for CH1, 1 for CH2
154+
@returns False if any I2C error occured
155+
*/
156+
/**************************************************************************/
157+
bool Adafruit_NAU7802::setChannel(uint8_t channel) {
158+
if (channel > 1)
159+
channel = 1;
160+
161+
Adafruit_I2CRegister ctrl2_reg = Adafruit_I2CRegister(i2c_dev, NAU7802_CTRL2);
162+
Adafruit_I2CRegisterBits ch_select =
163+
Adafruit_I2CRegisterBits(&ctrl2_reg, 1, 7); // # bits, bit_shift
164+
165+
return ch_select.write(channel);
166+
}
167+
150168
/**************************************************************************/
151169
/*!
152170
@brief Read the stored 24-bit ADC output value.

Adafruit_NAU7802.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class Adafruit_NAU7802 {
8585
bool available(void);
8686
int32_t read(void);
8787

88+
bool setChannel(uint8_t channel);
8889
bool setLDO(NAU7802_LDOVoltage voltage);
8990
NAU7802_LDOVoltage getLDO(void);
9091
bool setGain(NAU7802_Gain gain);

0 commit comments

Comments
 (0)