Implement a SD card into HW6
Dependencies: SDFileSystem mbed
Fork of shomberg_hw_6 by
main.cpp@9:da0b72918880, 2018-10-25 (annotated)
- Committer:
- rshomberg
- Date:
- Thu Oct 25 18:12:33 2018 +0000
- Revision:
- 9:da0b72918880
- Parent:
- 8:d6560caeda9a
- Child:
- 10:c9a438114fbd
does not compile
Who changed what in which revision?
User | Revision | Line number | New 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 | 9:da0b72918880 | 22 | #include "OCE360Input.h" |
rshomberg | 9:da0b72918880 | 23 | #include "SegDisplay.h" |
rshomberg | 0:82635173a413 | 24 | |
rshomberg | 0:82635173a413 | 25 | |
rshomberg | 0:82635173a413 | 26 | // OUTPUTS |
rshomberg | 2:312a0a9c4485 | 27 | Serial pc(USBTX, USBRX); // for debugging |
rshomberg | 6:8cfa0216554f | 28 | |
rshomberg | 0:82635173a413 | 29 | // VARIABLES |
rshomberg | 6:8cfa0216554f | 30 | int outputT= 0; |
rshomberg | 6:8cfa0216554f | 31 | float v0; |
rshomberg | 6:8cfa0216554f | 32 | float deltav; |
rshomberg | 6:8cfa0216554f | 33 | float val; |
rshomberg | 6:8cfa0216554f | 34 | int ones; |
rshomberg | 6:8cfa0216554f | 35 | int tens; |
rshomberg | 6:8cfa0216554f | 36 | |
rshomberg | 0:82635173a413 | 37 | |
rshomberg | 0:82635173a413 | 38 | int main() { |
rshomberg | 6:8cfa0216554f | 39 | // read starting voltage from temperature sensor |
rshomberg | 9:da0b72918880 | 40 | v0 = read_sensor(); |
rshomberg | 6:8cfa0216554f | 41 | |
rshomberg | 0:82635173a413 | 42 | while(1) { |
rshomberg | 6:8cfa0216554f | 43 | // Read Switch if on output temp else output mV |
rshomberg | 9:da0b72918880 | 44 | outputT = read_switch(); |
rshomberg | 9:da0b72918880 | 45 | deltav = read_sensor()-v0; |
rshomberg | 1:cbee04784c60 | 46 | |
rshomberg | 6:8cfa0216554f | 47 | // Output to terminal |
rshomberg | 6:8cfa0216554f | 48 | if (outputT) { |
rshomberg | 6:8cfa0216554f | 49 | // Convert to temp |
rshomberg | 9:da0b72918880 | 50 | val = convert_mV_to_temp(deltav); |
rshomberg | 9:da0b72918880 | 51 | //printf("Temperature Difference = %1.2f degC\n\r", val); |
rshomberg | 6:8cfa0216554f | 52 | } |
rshomberg | 6:8cfa0216554f | 53 | |
rshomberg | 6:8cfa0216554f | 54 | else { |
rshomberg | 6:8cfa0216554f | 55 | val = deltav; |
rshomberg | 9:da0b72918880 | 56 | //printf("Voltage Difference = %1.2f mV\n\r", val); |
rshomberg | 6:8cfa0216554f | 57 | } |
rshomberg | 4:098e3d869055 | 58 | |
rshomberg | 6:8cfa0216554f | 59 | // Convert val to ones and tens char |
rshomberg | 6:8cfa0216554f | 60 | ones = fmod(rint(val),10); |
rshomberg | 6:8cfa0216554f | 61 | tens = fmod(rint(val) / 10, 10); |
rshomberg | 1:cbee04784c60 | 62 | |
rshomberg | 6:8cfa0216554f | 63 | |
rshomberg | 9:da0b72918880 | 64 | Seg1 = SegConvert(ones); |
rshomberg | 9:da0b72918880 | 65 | Seg2 = SegConvert(tens); |
rshomberg | 6:8cfa0216554f | 66 | |
rshomberg | 6:8cfa0216554f | 67 | |
rshomberg | 6:8cfa0216554f | 68 | wait(1); |
rshomberg | 6:8cfa0216554f | 69 | |
rshomberg | 0:82635173a413 | 70 | } |
rshomberg | 6:8cfa0216554f | 71 | |
rshomberg | 0:82635173a413 | 72 | } |
rshomberg | 6:8cfa0216554f | 73 |