AS7265x functions for setting integration time, LEDs, collecting/reading data
Dependents: IntegratingSphereController LaunchDay
Revision 1:4d4e07dcc694, committed 2019-04-05
- Comitter:
- nthompson22
- Date:
- Fri Apr 05 19:19:52 2019 +0000
- Parent:
- 0:3699cacb5a93
- Commit message:
- Working code that measures with BRT and records to an SD card. This version does not have the UV Sensor implemented
Changed in this revision
AS7265xfunctions.cpp | Show annotated file Show diff for this revision Revisions of this file |
AS7265xfunctions.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 3699cacb5a93 -r 4d4e07dcc694 AS7265xfunctions.cpp --- a/AS7265xfunctions.cpp Thu Jan 24 01:27:45 2019 +0000 +++ b/AS7265xfunctions.cpp Fri Apr 05 19:19:52 2019 +0000 @@ -7,6 +7,9 @@ #define REG_DEV_SEL 0x4F #define REG_LED_CONFIG 0x07 #define REG_INTEG_TIME 0x05 +#define REG_BANK_MODE 0x04 +#define REG_TEMP_SENSOR 0x06 +#define REG_GAIN_SET 0x04 AS7265x::AS7265x(I2C i2c, int addr) : _i2c(i2c) { _addr = addr; @@ -181,4 +184,26 @@ /* divides by 2.8 because the sensor takes the value put into the function and multiplies it by 2.8 to get the integration time in ms. This way, the user can input how many ms they want the integration time to be */ regWrite(REG_INTEG_TIME, setting); -} \ No newline at end of file +} + +/* sets the bank mode of the sensor to either 0, 1, or 2. The input must be shifted ovre by 2 bits because the bank mode +is controlled by bits 2 and 3 in this register */ +void AS7265x::setBank(int bankSetting) { //bank setting and gain are controlled by different bits in the same register + char currentBankAndGain = regRead(REG_BANK_MODE); + currentBankAndGain = bankSetting<<2 | (currentBankAndGain & 0xF3); /* keeps the same value in the rest of the register, but + replaces bits 2 and 3 with what the user inputs */ + regWrite(REG_BANK_MODE, currentBankAndGain); +} + +// reads the temperature from the temperature sensor that is constantly taking the on-chip temperature +float AS7265x::readTemp() { + return regRead(REG_TEMP_SENSOR); +} + +// can be set to setting 0, 1, 2, or 3. setting 0: 1x. setting 1: 3.7x. setting 2: 16x. setting 3: 64x. +void AS7265x::setGain(int gain) { //shifted over 4 because gain is controlled by bits 4 and 5 in this register + char currentBankAndGain = regRead(REG_GAIN_SET); + currentBankAndGain = gain<<4 | (currentBankAndGain & 0xCF); /* keeps the same value in the rest of the register, but replaces + bits 4 and 5 with whatever the user inputs */ + regWrite(REG_GAIN_SET, currentBankAndGain); //bank mode and gain are controlled by different bits in the same register +}
diff -r 3699cacb5a93 -r 4d4e07dcc694 AS7265xfunctions.h --- a/AS7265xfunctions.h Thu Jan 24 01:27:45 2019 +0000 +++ b/AS7265xfunctions.h Fri Apr 05 19:19:52 2019 +0000 @@ -11,6 +11,9 @@ AS7265x(I2C i2c, int addr); //constructor function uint16_t readData(int); //enter a number 1 through 18 to read the data from one of the channels void collectData(void); //run this function to collect one set of data from all channels + void setBank(int); + float readTemp(void); + void setGain(int); private: void selectDevice(int); //selects one of the 3 sensors, used in ledSwitch() and collectData() uint16_t getData(int); //gets data from one channel, used in collectData() to set up the _channels array with all of the data @@ -19,7 +22,5 @@ char regRead(char reg); I2C _i2c; int _addr; - int _integTime; - int _set; }; -#endif \ No newline at end of file +#endif