Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Example_DS3231_test
Alphasense.cpp
00001 #include "Alphasense.h" 00002 #include "Adafruit_ADS1015.h" 00003 00004 ALPHASENSE::ALPHASENSE(I2C* i2c, int num_chan_op1, int num_chan_op2, int we0, int ae0, int sensitivity, int n_sample) : _i2c(i2c), _num_chan_op1(num_chan_op1), _num_chan_op2(num_chan_op2), _we0(we0), _ae0(ae0), _sensitivity(sensitivity), _n_sample(n_sample) { 00005 } 00006 00007 float ALPHASENSE::measure() { 00008 double we_result, ae_result; 00009 float result; 00010 int we, ae, we_integral, ae_integral; 00011 00012 Adafruit_ADS1115 ads(_i2c); //init ads1115 00013 ads.setGain(GAIN_TWO); //set range to 2.048 V 00014 00015 for (int i=0; i<_n_sample; i++) 00016 { 00017 we = ads.readADC_SingleEnded(_num_chan_op1); // read channel 00018 ae = ads.readADC_SingleEnded(_num_chan_op2); 00019 we_integral += we; 00020 ae_integral += ae; 00021 } 00022 00023 we_result = we_integral / _n_sample; //smoothing result 00024 ae_result = ae_integral / _n_sample; 00025 00026 we_result = we_result * 0.0625; //conversion to mV (2048 / 65536) 00027 ae_result = ae_result * 0.0625; 00028 00029 we_integral = 0; //reset integral 00030 ae_integral = 0; 00031 00032 result = (((we_result - _we0) - (ae_result - _ae0)) / _sensitivity) * 1000; //conversion to ppb 00033 00034 return result; 00035 }
Generated on Sun Jul 24 2022 04:33:35 by
1.7.2