Modular Programming

Dependencies:   mbed

main.cpp

Committer:
ccschneider
Date:
2018-12-23
Revision:
0:00336127c4e9

File content as of revision 0:00336127c4e9:

//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);
        }

    }
}