Grove Temp sensor Hello world example

Dependencies:   Grove_temp_sensor mbed

Files at this revision

API Documentation at this revision

Comitter:
peipei123
Date:
Wed Mar 09 00:00:46 2016 +0000
Child:
1:e3c235c7edaf
Commit message:
Hello world Example

Changed in this revision

Grove_temp_sensor.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Grove_temp_sensor.h	Wed Mar 09 00:00:46 2016 +0000
@@ -0,0 +1,33 @@
+#include "mbed.h"
+
+//Setup a new class for Grove_temp_sensor sensor
+class Grove_temp_sensor
+{
+public:
+    Grove_temp_sensor(PinName pin);
+    Grove_temp_sensor();
+    float read();
+private:
+//class sets up the AnalogIn pin
+    AnalogIn _pin;
+};
+
+Grove_temp_sensor::Grove_temp_sensor(PinName pin) : _pin(pin)
+{
+// _pin(pin) means pass pin to the AnalogIn constructor
+}
+
+float Grove_temp_sensor::read()
+{
+
+        double a;
+        a=_pin.read()*1023;
+        double resistance=(float)(1023-a)*10000/a;
+        double temperature=1/(log(resistance/10000)/3975+1/298.15)-276.05;
+        //conver C to F;
+        temperature = (9.0*temperature)/5.0 + 32.0;
+    return temperature;
+}
+
+
+        
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Mar 09 00:00:46 2016 +0000
@@ -0,0 +1,11 @@
+#include "mbed.h"
+#include "Grove_temp_sensor.h"
+AnalogIn Grove_temp_sensor(p15);
+
+int main() {
+    double temp;
+    while(1) {
+      temp = Grove_temp_sensor.read();
+      printf("The temperature is: %5.2F C \n\r", temp);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Mar 09 00:00:46 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/87f2f5183dfb
\ No newline at end of file