Read the temperaure in celsius and then convert to Fahrenheit degrees, and also display the value on the serial port.
Dependencies: Hotboards_temp mbed
main.cpp
00001 #include "mbed.h" 00002 /* 00003 Hotboards temp Library - Farenheit degrees 00004 Read the temperaure in celsius and then convert to Farenheit degrees, and also display 00005 the value on the serial port. 00006 The circuit 00007 * VDD --> 3.3v 00008 * SDA --> PB_9 00009 * SCL --> PB_8 00010 * ALERT --> PB_13 00011 * GND --> GND 00012 Library and example created by Diego from Hotboards 00013 Ported to mbed by Pedro from Hotboards 00014 This example code is in the public domain. 00015 */ 00016 #include "mbed.h" 00017 #include "Hotboards_temp.h" 00018 00019 Serial pc(USBTX, USBRX); 00020 //I2C bus instance for the library 00021 I2C device( I2C_SDA, I2C_SCL ); 00022 // instance a sensor with address number 7 (none of the jumpers on the board is short circuited) 00023 // and also 0.5 celsius degrees resolution 00024 Hotboards_temp sensor( device, Sensor_7); 00025 00026 00027 00028 int main( void ) 00029 { 00030 00031 // init sensor 00032 sensor.init(); 00033 00034 while(1) 00035 { 00036 // read temperature in celcius degrees 00037 float temp = sensor.read(); 00038 // convert celcius to fahrenheit 00039 float tempF = sensor.CelsiusToFarenheit( temp); 00040 // print it on the serial port 00041 pc.printf("Temp sensor : %3.1f F\r\n",tempF); 00042 // take the next value after 2 sec (just to not read too often) 00043 wait(2); 00044 } 00045 }
Generated on Wed Jul 13 2022 17:15:04 by 1.7.2