MSOE EE2905 / Mbed 2 deprecated Audible_Thermometer

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
rossatmsoe
Date:
Thu Oct 05 20:02:27 2017 +0000
Commit message:
Thermometer (using thermistor) that creates beeps of increasing pitch and pulse rate as temperature rises above nominal. Demonstrates use of #include for your own header files, and #define for constants.

Changed in this revision

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
thermistor.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 59f09202ccbb main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Oct 05 20:02:27 2017 +0000
@@ -0,0 +1,57 @@
+/*  Audible Thermometer
+
+Creates beeps of increasing pitch and pulse rate as the temperature
+rises above the nominal value.
+
+Hardware:   10k resistor from A0 to ground
+            10k nominal thermistor from A0 to 3V3
+            Speaker from D9 to ground
+
+*/
+
+#include "mbed.h"
+#include "thermistor.h"   // This file contains the temperature calculation
+
+#define  NOMINAL_TEMP  75  // Change the nominal temperature here
+
+AnalogIn therm(A0);
+PwmOut speaker(D9);
+Serial pc(USBTX,USBRX);
+
+// This function will be defined in this file, main.cpp
+void beep(float freq, float duration);
+
+int main()
+{
+    while(1) {
+        
+        // Calculate Temperature
+        int tempF = temp_calc(therm);  // This function is in thermistor.h
+        
+        // Calculate difference from nominal
+        int difference = tempF-NOMINAL_TEMP;
+        
+        // If I have a fever...
+        if (difference >= 1) {
+            
+            // Create a warning beep that gets higher in pitch and
+            // more rapid as temperature increases
+            float frequency = difference*100;
+            float duration = .5/difference;
+            
+            // Call beeping function defined below
+            beep(frequency,duration);
+            
+            wait(duration);
+        }
+    }
+}
+
+void beep(float freq, float duration)   // Note that one of the variables
+{                                       // in the note() function has the same
+    speaker.period(1/freq);             // as a variable in main().
+    speaker=.5;                         // That's ok, since they are local
+    wait(duration);                     // to their respective functions.
+    speaker=0;                          // This function also uses a global
+}                                       // variable, speaker.
+
diff -r 000000000000 -r 59f09202ccbb mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Oct 05 20:02:27 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/235179ab3f27
\ No newline at end of file
diff -r 000000000000 -r 59f09202ccbb thermistor.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/thermistor.h	Thu Oct 05 20:02:27 2017 +0000
@@ -0,0 +1,16 @@
+/* thermistor.h
+
+   Contains the definition for the Fahrenheit temperature calculation
+   
+   The input is the analog reading, and the returned float value is the
+   temperature in degrees Fahrenheit.
+
+*/
+
+float temp_calc(float analog_value) {
+        double R_ratio = (1/analog_value - 1);
+        double logR_ratio=log(R_ratio);
+        double T_kelvin=1/(.003354016+.000256985*logR_ratio+.000002620131*logR_ratio*logR_ratio);
+        float T = 1.8*(T_kelvin - 273) + 32;
+        return T;
+}
\ No newline at end of file