Test Temperature Sensor(DS18B20) for LPC11U68 Xpresso v2

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 DigitalOut myled(LED1);
00005 Serial serial(USBTX, USBRX);
00006 DS18B20Sensor sensor(P1_25);
00007 // I set P1_25 here, but it's not affected code. (looked into library..no use this pinname)
00008 // Instead of this line, please refer to define statment of "onewire.h".
00009 // Thanks Steve Spence @ <<library /users/jsteve/code/DS18B20Sensor/>>
00010 
00011 int main()
00012 {
00013     uint8_t result;
00014     uint8_t i;
00015     char sensorBuf[25];
00016 
00017     serial.printf("Temperature Sensor DS18B20 Test.\rFound %d sensors\r", sensor.count());
00018     while(1) {
00019         myled = 1;
00020         wait(0.2);
00021         myled = 0;
00022         wait(0.2);
00023         result = sensor.startReading(true);     // start sensor readings and wait
00024         if (result == DS18X20_OK) {
00025             for (i = 0; i < sensor.count(); i++) {
00026                 sensor.getReading(sensorBuf, i);         // get result into buf
00027                 serial.printf("Sensor %d : %s\r", i+1, sensorBuf);  // display it to the world
00028             }
00029         } else {
00030             serial.printf("Sensor Reading Error (%d)\r", result);  // display it to the world
00031 
00032         }
00033 
00034     }
00035 }