TVZ2022 / Mbed 2 deprecated Dominik_Plepelic_Regulator_Temperature

Dependencies:   mbed tempRegulator

Revision:
0:e2969f655e3e
Child:
1:bee82719a604
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Dec 01 08:54:40 2022 +0000
@@ -0,0 +1,184 @@
+#include "mbed.h"
+#include "tempRegulator.h"
+#include "SegDisplay.h"
+
+
+AnalogIn LM35(PA_0); // Setting pin PA0 (A0) as Anlog Input
+AnalogIn ana2(PA_1); // Setting pin PA1 (A0) as Anlog Input
+DigitalOut led1(LED1);
+DigitalOut fanOut(D2);
+Ticker measure;
+Serial pc(SERIAL_TX, SERIAL_RX); // Create an object of Serial Class
+char SegConvert(char SegValue);
+void takeMasurement(void);
+void setTemperatureLimit(void);
+InterruptIn confirm(PC_13);
+Timer debounce;
+Timer timer1;
+
+int blinky = 1;
+int tempLimit = 100;
+float temperature;
+int huh;
+int n;
+
+void takeMasurement()
+{                       
+        if (temperature > tempLimit){
+                led1 = 1;
+                fanOut = 1;
+            }
+        else if (temperature < (tempLimit - 2) ){
+            led1 = 0;
+            fanOut = 0;
+            }
+    
+     
+}
+
+int main()
+{
+    confirm.rise(&setTemperatureLimit);
+   measure.attach(&takeMasurement,2);
+     timer1.start();
+    debounce.start();
+   
+
+    while (1) {
+        
+        
+        temperature = getTemps(LM35);
+            huh = temperature * 10 ;
+            pc.printf("lm35 = %.1f ^C\r\n", temperature);
+           Seg3 = SegConvert((int)(huh % 10));
+            Seg2 = SegConvertDot( ((int)temperature)%10);
+            Seg1 = SegConvert(int(temperature/10));
+            
+            wait(1);
+       
+
+    }
+    
+}
+
+void setTemperatureLimit()
+{
+        
+        timer1.reset();
+    if (debounce.read_ms()>500) {
+       
+        
+        pc.printf("getting limit for temps \n");
+        while (1) {
+            
+            Seg3 = SegConvert(10);
+
+            int currentInput = getMaxTemp(ana2);
+            pc.printf("%i \n\r", currentInput);
+            if (blinky < 5) {
+
+                Seg2 = SegConvert(currentInput % 10);
+                Seg1 = SegConvert(currentInput / 10);
+                blinky++;
+            } else if (blinky > 4 && blinky <6) {
+                Seg2 = SegConvert(10);
+                Seg1 = SegConvert(10);
+                blinky++;
+            } else {
+                blinky = 1;
+            }
+
+            if (confirm == 0) {
+                pc.printf("limit get: %i \n", currentInput);
+                Seg2 = SegConvert(currentInput % 10);
+                Seg1 = SegConvert(currentInput / 10);
+                tempLimit = currentInput;
+                wait(1);
+                break;
+            }
+            if (timer1.read_ms()>=20000){
+                break;
+                }
+        }
+
+
+        debounce.reset();
+    }
+
+}
+/*
+char SegConvert(char SegValue)   // function 'SegConvert'
+{
+    char SegByte = 0x00;
+    switch (SegValue) { // DP G F E D C B A
+        case 0:
+            SegByte = 0x3F;
+            break; // 0 0 1 1 1 1 1 1 binary
+        case 1:
+            SegByte = 0x06;
+            break; // 0 0 0 0 0 1 1 0 binary
+        case 2:
+            SegByte = 0x5B;
+            break; // 0 1 0 1 1 0 1 1 binary
+        case 3:
+            SegByte = 0x4F;
+            break; // 0 1 0 0 1 1 1 1 binary
+        case 4:
+            SegByte = 0x66;
+            break; // 0 1 1 0 0 1 1 0 binary
+        case 5:
+            SegByte = 0x6D;
+            break; // 0 1 1 0 1 1 0 1 binary
+        case 6:
+            SegByte = 0x7D;
+            break; // 0 1 1 1 1 1 0 1 binary
+        case 7:
+            SegByte = 0x07;
+            break; // 0 0 0 0 0 1 1 1 binary
+        case 8:
+            SegByte = 0x7F;
+            break; // 0 1 1 1 1 1 1 1 binary
+        case 9:
+            SegByte = 0x6F;
+            break; // 0 1 1 0 1 1 1 1 binary
+        case 10:
+            SegByte = 0x00;
+            break; // 0 1 1 0 1 1 1 1 binary
+    }
+    return SegByte;
+}*/
+
+/*
+void getTemps(AnalogIn LM35){
+    float tempC,tempF,a[30],avg;
+    int i;
+
+
+    avg=0;
+        for(i=0; i<20; i++) {
+            avg+=LM35.read() / 20;
+            wait(.03);
+        }
+
+
+        tempC=(avg*3.3*100);
+        pc.printf("tempC %f", tempC);
+        float temp = tempC - (int)tempC;
+        if(temp > 0.25 && temp < 0.75){
+            tempC = (int)tempC + 0.5;
+            }
+        else if (temp > 0 && temp < 0.25) {
+            tempC = (int)tempC;
+            }
+        else if (temp > 0.75){
+            tempC = (int)tempC + 1;
+            }
+        pc.printf("avg %f", tempC);
+
+
+        tempF=(9.0*tempC)/5.0 + 32.0;
+        pc.printf("temperature = %.1f ^C\r\n", tempC);
+
+    }
+    */
+