DS18B20 with serial PC

Dependencies:   DS18B20Sensor

Files at this revision

API Documentation at this revision

Comitter:
SereinTT
Date:
Tue Dec 04 16:04:15 2018 +0000
Parent:
1:901bf6de682c
Commit message:
DS18B20;

Changed in this revision

main.cpp Show diff for this revision Revisions of this file
main1.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 901bf6de682c -r 1573a160c634 main.cpp
--- a/main.cpp	Tue Dec 04 15:15:45 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-#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;
-    }
-}
diff -r 901bf6de682c -r 1573a160c634 main1.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main1.cpp	Tue Dec 04 16:04:15 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 ",  atof (sensorBuf));
+  }
+if (atof (sensorBuf)>25){
+    myled=1;
+    }
+    else{
+    myled=0;
+    }
+}