Russell Shomberg
/
shomberg_hw_6
HW6 for OCE560
Fork of shomberg_hw_5 by
SegDisplay.cpp@12:ea407dcaff78, 2018-10-25 (annotated)
- Committer:
- rshomberg
- Date:
- Thu Oct 25 22:43:36 2018 +0000
- Revision:
- 12:ea407dcaff78
- Parent:
- 11:42914083ac70
- Child:
- 13:fa74bf0c3b8d
made SegWrite function and moved pin assignments to header files. This does not work.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rshomberg | 9:da0b72918880 | 1 | /** |
rshomberg | 9:da0b72918880 | 2 | Temperature Sensor for hw6 |
rshomberg | 9:da0b72918880 | 3 | SegDisplay.cpp |
rshomberg | 9:da0b72918880 | 4 | |
rshomberg | 9:da0b72918880 | 5 | Purpose: Convert an integer value to a hex |
rshomberg | 9:da0b72918880 | 6 | Hex output represents binary required to make a 7-seg led show the integer value |
rshomberg | 9:da0b72918880 | 7 | Pin configuration for 7-Seg |
rshomberg | 9:da0b72918880 | 8 | ones: 12 13 14 15 16 17 18 19 |
rshomberg | 9:da0b72918880 | 9 | A B C D E F G P |
rshomberg | 9:da0b72918880 | 10 | tens: 21 22 23 24 25 26 27 28 |
rshomberg | 9:da0b72918880 | 11 | |
rshomberg | 9:da0b72918880 | 12 | @author Russell Shomberg |
rshomberg | 9:da0b72918880 | 13 | @created 2018-10-23 |
rshomberg | 9:da0b72918880 | 14 | @revised 2018-10-25 |
rshomberg | 9:da0b72918880 | 15 | @version 0.0 |
rshomberg | 9:da0b72918880 | 16 | |
rshomberg | 9:da0b72918880 | 17 | Issues: No Decimal point for temperature |
rshomberg | 9:da0b72918880 | 18 | |
rshomberg | 9:da0b72918880 | 19 | */ |
rshomberg | 9:da0b72918880 | 20 | |
rshomberg | 9:da0b72918880 | 21 | // INCLUDES |
rshomberg | 9:da0b72918880 | 22 | #include "mbed.h" |
rshomberg | 9:da0b72918880 | 23 | #include "SegDisplay.h" |
rshomberg | 9:da0b72918880 | 24 | |
rshomberg | 12:ea407dcaff78 | 25 | int ones; |
rshomberg | 12:ea407dcaff78 | 26 | int tens; |
rshomberg | 12:ea407dcaff78 | 27 | |
rshomberg | 12:ea407dcaff78 | 28 | |
rshomberg | 11:42914083ac70 | 29 | |
rshomberg | 9:da0b72918880 | 30 | char SegConvert(int SegValue) { // function 'SegConvert' |
rshomberg | 9:da0b72918880 | 31 | char SegByte=0x00; |
rshomberg | 9:da0b72918880 | 32 | switch (abs(SegValue)) { // ABCDEFGP |
rshomberg | 9:da0b72918880 | 33 | case 0 : SegByte= 0x3F;break; // 11111100 binary |
rshomberg | 9:da0b72918880 | 34 | case 1 : SegByte= 0x06;break; // 01100000 binary |
rshomberg | 9:da0b72918880 | 35 | case 2 : SegByte= 0x5B;break; // 11110110 binary |
rshomberg | 9:da0b72918880 | 36 | case 3 : SegByte= 0x4F;break; // 10011110 binary |
rshomberg | 9:da0b72918880 | 37 | case 4 : SegByte= 0x66;break; // 11001100 binary |
rshomberg | 9:da0b72918880 | 38 | case 5 : SegByte= 0x6D;break; // 11011010 binary |
rshomberg | 9:da0b72918880 | 39 | case 6 : SegByte= 0x7D;break; // 11111010 binary |
rshomberg | 9:da0b72918880 | 40 | case 7 : SegByte= 0x07;break; // 00001110 binary |
rshomberg | 9:da0b72918880 | 41 | case 8 : SegByte= 0x7F;break; // 11111110 binary |
rshomberg | 9:da0b72918880 | 42 | case 9 : SegByte= 0x6F;break; // 11011110 binary |
rshomberg | 9:da0b72918880 | 43 | } |
rshomberg | 9:da0b72918880 | 44 | return ~SegByte; |
rshomberg | 12:ea407dcaff78 | 45 | } |
rshomberg | 12:ea407dcaff78 | 46 | |
rshomberg | 12:ea407dcaff78 | 47 | void SegWrite(float val){ |
rshomberg | 12:ea407dcaff78 | 48 | // Convert val to ones and tens char |
rshomberg | 12:ea407dcaff78 | 49 | ones = fmod(rint(val),10); |
rshomberg | 12:ea407dcaff78 | 50 | tens = fmod(rint(val) / 10, 10); |
rshomberg | 12:ea407dcaff78 | 51 | |
rshomberg | 12:ea407dcaff78 | 52 | Seg1 = SegConvert(ones); |
rshomberg | 12:ea407dcaff78 | 53 | Seg2 = SegConvert(tens); |
rshomberg | 9:da0b72918880 | 54 | } |