edge / Mbed 2 deprecated EdgeTeamTest

Dependencies:   libmDot mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002  
00003 // veranderd!
00004  
00005 // Read temperature from TH06
00006 
00007 // p6   PA_8 / XBEE_PWM0 / XBEE_RSSI / I2C_SCL  D15
00008 // p7   PC_9 / XBEE_PWM1 / I2C_SDA              D14
00009 I2C i2c(PC_9,PA_8);
00010 
00011 const int addr = 0x80;
00012 
00013 int main() {
00014     char cmd[2];
00015     
00016     while (1) {
00017         cmd[0] = 0xf3;
00018         i2c.write(addr, cmd, 1);
00019  
00020         wait(0.5);
00021  
00022         i2c.read(addr, cmd, 2);
00023  
00024         float temp_code = (cmd[0]<<8)|cmd[1];
00025         float temp = 175.72*temp_code/65535.0-46.85;
00026         
00027         printf("Temp = %.2f\r\n", temp);
00028     }
00029 }