Kuldip Maharjan
/
i2c_temperature
Reads temperature input in mbed using i2c and prints it to computer terminal through serial
main.cpp
- Committer:
- kuldipmaharjan
- Date:
- 2014-01-08
- Revision:
- 0:f003b8445395
File content as of revision 0:f003b8445395:
//Author: Kuldip Maharjan //Email : kuldipmaharjan@gmail.com //Anyone can use this code if it helps in their projects or //for learning programing in mbed besides for commercial purposes //Reads temperature input in mbed using i2c and prints it to computer terminal through serial #include "mbed.h" I2C i2c( p28, p27 ); // sda, scl AnalogIn temperature(p20); Serial pc(USBTX, USBRX); // tx, rx int main() { char v[2]; char cmd[2]; pc.baud(115200); i2c.frequency(100000); cmd[0] = 0x0C; cmd[1] = 0x0D; pc.printf("kuldip"); while(1) { i2c.write( 0x34, cmd , 2 , true); i2c.read( 0x34, v, 2 ); wait(1); pc.printf("v[0] = %d.%d %%\t", v[0],v[1]); } }