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.
Diff: YKNCT_I2C.cpp
- Revision:
- 0:c555f844eb8d
- Child:
- 1:67d5ea2ff6c1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/YKNCT_I2C.cpp Tue Apr 02 07:18:26 2019 +0000 @@ -0,0 +1,23 @@ +#include "YKNCT_I2C.h" + +Y_I2C::Y_I2C(PinName sda, PinName scl) : i2c(sda, scl) +{ + i2c.frequency(100000); +} + +int Y_I2C::Adc(int address, int num) +{ + static char data[8]= {0}; + static int ad_data[4]= {0}; + + i2c.read(address<<1, data, 8, false); + + for(int i=0; i<4; i++) + ad_data[i]=(int16_t)data[i*2+1]<<8|data[i*2]; + + return ad_data[num]; +} + + + +