Modular Programming

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
ccschneider
Date:
Sun Dec 23 17:07:47 2018 +0000
Commit message:
Modular Programming;

Changed in this revision

SegDisplay.cpp Show annotated file Show diff for this revision Revisions of this file
SegDisplay.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/SegDisplay.cpp	Sun Dec 23 17:07:47 2018 +0000
@@ -0,0 +1,51 @@
+#include "SegDisplay.h"
+
+BusOut Seg1(p12,p13,p14,p15,p16,p17,p18,p19); // A,B,C,D,E,F,G,DP (tens place)
+BusOut Seg2(p21,p22,p23,p24,p25,p26,p27,p28); // A,B,C,D,E,F,G,DP (ones place)
+
+void SegInit(void)
+{
+
+    Seg1 = SegConvert(0); // initialise to zero
+    Seg2 = SegConvert(0); // initialise to zero
+}
+
+char SegConvert(int SegValue) // function to convert a number to a 7-segment byte
+{
+    char SegByte=0x00;
+    switch (SegValue) {                // DPGFEDCBA
+        case 0 :
+            SegByte = 0xC0;
+            break; // 00111111 binary
+        case 1 :
+            SegByte = 0xF9;
+            break; // 00000110 binary
+        case 2 :
+            SegByte = 0xA4;
+            break; // 01011011 binary
+        case 3 :
+            SegByte = 0xB0;
+            break; // 01001111 binary
+        case 4 :
+            SegByte = 0x99;
+            break; // 01100110 binary
+        case 5 :
+            SegByte = 0x92;
+            break; // 01101101 binary
+        case 6 :
+            SegByte = 0x82;
+            break; // 01111101 binary
+        case 7 :
+            SegByte = 0xF8;
+            break; // 00000111 binary
+        case 8 :
+            SegByte = 0x80;
+            break; // 01111111 binary
+        case 9 :
+            SegByte = 0x90;
+            break; // 01101111 binary
+    }
+    return SegByte;
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SegDisplay.h	Sun Dec 23 17:07:47 2018 +0000
@@ -0,0 +1,12 @@
+#include "mbed.h"
+
+#ifndef SEGDISPLAY_H
+#define SEGDISPLAY_H
+
+extern BusOut Seg1; // allow Seg1 to be manipulated by other files
+extern BusOut Seg2; // allow Seg2 to be manipulated by other files
+
+void SegInit(void); // function prototype
+char SegConvert(char SegValue); // function prototype
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Dec 23 17:07:47 2018 +0000
@@ -0,0 +1,52 @@
+//Cecilia Schneider
+//OCE 360 HW #6 October 25,2018
+
+#include "mbed.h"
+#include "SegDisplay.h"
+
+#define mV_Volt 3300
+#define TMP36_calib 500
+
+Serial pc(USBTX, USBRX); //comms to host PC
+AnalogIn TMP36(p20); // temperature sensor input on p20
+DigitalIn s1(p11); // switch on p11
+
+char SegConvert(char SegValue); // function to convert a number to a 7-segment byte
+float temp = TMP36; // converts analog input to float
+int tempmV = (temp*(mV_Volt))-TMP36_calib; // float in volts to int in mV
+int tempC = tempmV / 10; // int in mV to degrees C
+
+int main()
+{
+    while (1) {
+        float temp1 = TMP36; //new analog input to float
+        int tempmV1 =(temp1*(mV_Volt))-TMP36_calib; // float (V) to int (mV)
+        int tempC1 = tempmV1 / 10; // int in mV to degrees C
+        int voltdiff = tempmV - tempmV1;
+        int tempdiff = tempC - tempC1;
+        
+        if (s1 == 1){
+            int ones = voltdiff % 10; // find the remainder for units column
+            int tens = voltdiff / 10; // find the remainder for tens column
+            Seg2 = SegConvert(abs(ones)); // units column
+            Seg1 = SegConvert(abs(tens)); // tens column
+            // Continuously Output to the Terminal
+            pc.printf("Original mV: %d \r\n",tempmV); 
+            pc.printf("New mV: %d \r\n",tempmV1); 
+            pc.printf("Difference mV: %d \r\n",voltdiff);
+            wait(1);
+        }
+        else {
+            int ones = tempdiff % 10; // find the remainder for units column
+            int tens = tempdiff / 10; // find the remainder for tens column
+            Seg2=SegConvert(abs(ones)); // units column
+            Seg1=SegConvert(abs(tens)); // tens column
+            // Continuously Output to the Terminal
+            pc.printf("Original Temp: %d \r\n",tempC); 
+            pc.printf("New Temp: %d \r\n",tempC1); 
+            pc.printf("Temp Diff: %d \r\n",tempdiff);
+            wait(1);
+        }
+
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Dec 23 17:07:47 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e95d10626187
\ No newline at end of file