HW6 for OCE560

Dependencies:   mbed

Fork of shomberg_hw_5 by Russell Shomberg

Committer:
rshomberg
Date:
Thu Oct 25 18:58:41 2018 +0000
Revision:
11:42914083ac70
Parent:
10:c9a438114fbd
Child:
12:ea407dcaff78
compiles, but using extern

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rshomberg 0:82635173a413 1 /**
rshomberg 8:d6560caeda9a 2 Temperature Sensor for hw6
rshomberg 0:82635173a413 3 main.cpp
rshomberg 0:82635173a413 4
rshomberg 6:8cfa0216554f 5 Purpose: Read signal from TMP36 connected to pin20
rshomberg 6:8cfa0216554f 6 Display output voltage to terminal
rshomberg 6:8cfa0216554f 7 Display difference in mV of output voltage to starting voltage on 2x 7-Segment Displays
rshomberg 6:8cfa0216554f 8 See outputs for pin configuration
rshomberg 6:8cfa0216554f 9 Toggle switch connected to pin07 to convert displays to degC
rshomberg 6:8cfa0216554f 10
rshomberg 8:d6560caeda9a 11 @author Russell Shomberg
rshomberg 8:d6560caeda9a 12 @created 2018-10-23
rshomberg 9:da0b72918880 13 @revised 2018-10-25
rshomberg 8:d6560caeda9a 14 @version 0.0
rshomberg 0:82635173a413 15
rshomberg 6:8cfa0216554f 16 Issues: No Decimal point for temperature
rshomberg 7:1a43ff8ccc08 17
rshomberg 5:dbd163551a58 18 */
rshomberg 0:82635173a413 19
rshomberg 0:82635173a413 20 // INCLUDES
rshomberg 0:82635173a413 21 #include "mbed.h"
rshomberg 11:42914083ac70 22 #include "SegDisplay.h"
rshomberg 9:da0b72918880 23 #include "OCE360Input.h"
rshomberg 0:82635173a413 24
rshomberg 0:82635173a413 25 // OUTPUTS
rshomberg 2:312a0a9c4485 26 Serial pc(USBTX, USBRX); // for debugging
rshomberg 6:8cfa0216554f 27
rshomberg 0:82635173a413 28 // VARIABLES
rshomberg 6:8cfa0216554f 29 int outputT= 0;
rshomberg 6:8cfa0216554f 30 float v0;
rshomberg 6:8cfa0216554f 31 float deltav;
rshomberg 6:8cfa0216554f 32 float val;
rshomberg 6:8cfa0216554f 33 int ones;
rshomberg 6:8cfa0216554f 34 int tens;
rshomberg 6:8cfa0216554f 35
rshomberg 0:82635173a413 36
rshomberg 0:82635173a413 37 int main() {
rshomberg 6:8cfa0216554f 38 // read starting voltage from temperature sensor
rshomberg 9:da0b72918880 39 v0 = read_sensor();
rshomberg 6:8cfa0216554f 40
rshomberg 0:82635173a413 41 while(1) {
rshomberg 6:8cfa0216554f 42 // Read Switch if on output temp else output mV
rshomberg 9:da0b72918880 43 outputT = read_switch();
rshomberg 9:da0b72918880 44 deltav = read_sensor()-v0;
rshomberg 1:cbee04784c60 45
rshomberg 6:8cfa0216554f 46 // Output to terminal
rshomberg 6:8cfa0216554f 47 if (outputT) {
rshomberg 6:8cfa0216554f 48 // Convert to temp
rshomberg 9:da0b72918880 49 val = convert_mV_to_temp(deltav);
rshomberg 9:da0b72918880 50 //printf("Temperature Difference = %1.2f degC\n\r", val);
rshomberg 6:8cfa0216554f 51 }
rshomberg 6:8cfa0216554f 52
rshomberg 6:8cfa0216554f 53 else {
rshomberg 6:8cfa0216554f 54 val = deltav;
rshomberg 9:da0b72918880 55 //printf("Voltage Difference = %1.2f mV\n\r", val);
rshomberg 6:8cfa0216554f 56 }
rshomberg 4:098e3d869055 57
rshomberg 6:8cfa0216554f 58 // Convert val to ones and tens char
rshomberg 6:8cfa0216554f 59 ones = fmod(rint(val),10);
rshomberg 6:8cfa0216554f 60 tens = fmod(rint(val) / 10, 10);
rshomberg 1:cbee04784c60 61
rshomberg 6:8cfa0216554f 62
rshomberg 9:da0b72918880 63 Seg1 = SegConvert(ones);
rshomberg 9:da0b72918880 64 Seg2 = SegConvert(tens);
rshomberg 6:8cfa0216554f 65
rshomberg 6:8cfa0216554f 66
rshomberg 6:8cfa0216554f 67 wait(1);
rshomberg 6:8cfa0216554f 68
rshomberg 0:82635173a413 69 }
rshomberg 6:8cfa0216554f 70
rshomberg 0:82635173a413 71 }
rshomberg 6:8cfa0216554f 72