Umair Aftab / Mbed 2 deprecated DS18B20Sensor

Dependencies:   DS18B20Sensor mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "DS18B20Sensor.h"
00003  
00004 // Instantiate sensor with hardware in pin p30 
00005 DS18B20Sensor sensor(PTB4);
00006  
00007 // Setup a window to the world
00008 //Serial pc(p13, p14);
00009 Serial pc(USBTX, USBRX);
00010  
00011 int main()
00012 {
00013    char sensorBuf[25];
00014  
00015    // count will search for sensors, if not already called
00016    pc.printf("Found %d sensor/s\r", sensor.count());
00017  
00018    uint8_t result = sensor.startReading(true);     // start sensor readings and wait
00019  
00020    for (uint8_t i = 0; i < sensor.count(); i++) {
00021       sensor.getReading(sensorBuf, i);         // get result into buf
00022       pc.printf("Sensor %d : %s\r", i+1, sensorBuf);  // display it to the world
00023    }
00024  
00025 }