DS18B20 with serial PC

Dependencies:   DS18B20Sensor

Revision:
1:901bf6de682c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Dec 04 15:15:45 2018 +0000
@@ -0,0 +1,35 @@
+#include "mbed.h"
+#include "DS18B20Sensor.h"
+
+// Instantiate sensor with hardware in pin p30 
+DS18B20Sensor sensor(p30);
+
+// Setup a window to the world
+Serial pc(USBTX, USBRX);
+//Serial pc(USBTX, USBRX);
+
+DigitalOut myled(LED1);
+
+int main()
+{
+  char sensorBuf[25];
+  float num;
+  // count will search for sensors, if not already called
+  pc.printf("Found %d sensor/s\r", sensor.count());
+
+  uint8_t result = sensor.startReading(true);     // start sensor readings and wait
+
+  for (uint8_t i = 0; i < sensor.count(); i++) {
+     sensor.getReading(sensorBuf, i);         // get result into buf
+     pc.printf("Sensor %d : %s\r", i+1, sensorBuf);  // display it to the world
+
+     num= atof (sensorBuf);
+     pc.printf("result: %.2f\r ",  num);
+  }
+if (num>25){
+    myled=1;
+    }
+    else{
+    myled=0;
+    }
+}