Hotboards MX / Mbed 2 deprecated Hotboards_temp_reading_temperature

Dependencies:   Hotboards_temp mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

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