Becky Page / Mbed OS Blinkcopy
Revision:
0:cd8526d38aea
Child:
1:448ff9efcefa
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Nov 20 15:14:39 2020 +0000
@@ -0,0 +1,49 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2019 ARM Limited
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#include "mbed.h"
+#include "platform/mbed_thread.h"
+
+
+// Blinking rate in milliseconds
+#define BLINKING_RATE_MS 500
+#define SW2 P0_4
+// #define alsOut P10_0
+
+
+
+int main()
+{
+    // Initialise the digital pin LED1 as an output
+    DigitalOut led(LED1);
+    DigitalIn pushButton(SW2, PullUp);
+    DigitalOut thermVcc(P10_3);
+    DigitalOut thermGnd(P10_0);
+    AnalogIn thermVal(P10_1);
+   
+    thermVcc = 1; 
+    thermGnd = 0; 
+    while (true) {
+        if (pushButton == 0)
+        {
+        led=!led;
+        /*read thermistor Voltage*/ 
+            float refVoltage = thermVal.read() * 2.4;// Range of ADC 0->2*Vref
+            float refCurrent = refVoltage / 10000.0; //10k Reference Resistor
+            float therVoltage = 3.3 - refVoltage; // Assume supply voltage is 3.3v
+            float thermResistance = therVoltage / refCurrent;
+            float logrT = (float32_t)log((float64_t)thermResistance);
+            
+            /*Calculate temperature from the resistance of thermistor using Steinhart-Hart Equation*/
+            float stEqn = (float32_t) ((0.0009032679) + ((0.000248772) * logrT) + ((2.041094E-07) * pow((float64)logrT, (float32)3)));
+                                     
+            float temperatureC = (float32_t)(((1.0 / stEqn) - 273.15) + 0.5); 
+            
+                        
+            printf("Temerpature is %f C\r\n", temperatureC);
+            }
+        thread_sleep_for(BLINKING_RATE_MS);
+    }
+}