HW6 for OCE560

Dependencies:   mbed

Fork of shomberg_hw_5 by Russell Shomberg

Committer:
rshomberg
Date:
Tue Oct 30 14:08:21 2018 +0000
Revision:
13:fa74bf0c3b8d
Parent:
12:ea407dcaff78
Child:
14:b3c87a7c7689
working code

Who changed what in which revision?

UserRevisionLine numberNew 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 13:fa74bf0c3b8d 25 // INPUTS
rshomberg 13:fa74bf0c3b8d 26 BusOut Seg1(p12,p13,p14,p15,p16,p17,p18,p19); //01 02 03 04 05 06 07 08 09 10
rshomberg 13:fa74bf0c3b8d 27 BusOut Seg2(p21,p22,p23,p24,p25,p26,p27,p28); //E D CC C DP B A CC F G
rshomberg 12:ea407dcaff78 28
rshomberg 13:fa74bf0c3b8d 29 int ones; // ones digit of output
rshomberg 13:fa74bf0c3b8d 30 int tens; // tens digit of output
rshomberg 11:42914083ac70 31
rshomberg 9:da0b72918880 32 char SegConvert(int SegValue) { // function 'SegConvert'
rshomberg 13:fa74bf0c3b8d 33 // Converts a integer value to a hexidecimal output
rshomberg 13:fa74bf0c3b8d 34 // the output corresponds to a bus connected to the segdisplay
rshomberg 13:fa74bf0c3b8d 35 // bus recreates the original integer
rshomberg 9:da0b72918880 36 char SegByte=0x00;
rshomberg 9:da0b72918880 37 switch (abs(SegValue)) { // ABCDEFGP
rshomberg 9:da0b72918880 38 case 0 : SegByte= 0x3F;break; // 11111100 binary
rshomberg 9:da0b72918880 39 case 1 : SegByte= 0x06;break; // 01100000 binary
rshomberg 9:da0b72918880 40 case 2 : SegByte= 0x5B;break; // 11110110 binary
rshomberg 9:da0b72918880 41 case 3 : SegByte= 0x4F;break; // 10011110 binary
rshomberg 9:da0b72918880 42 case 4 : SegByte= 0x66;break; // 11001100 binary
rshomberg 9:da0b72918880 43 case 5 : SegByte= 0x6D;break; // 11011010 binary
rshomberg 9:da0b72918880 44 case 6 : SegByte= 0x7D;break; // 11111010 binary
rshomberg 9:da0b72918880 45 case 7 : SegByte= 0x07;break; // 00001110 binary
rshomberg 9:da0b72918880 46 case 8 : SegByte= 0x7F;break; // 11111110 binary
rshomberg 9:da0b72918880 47 case 9 : SegByte= 0x6F;break; // 11011110 binary
rshomberg 9:da0b72918880 48 }
rshomberg 9:da0b72918880 49 return ~SegByte;
rshomberg 12:ea407dcaff78 50 }
rshomberg 12:ea407dcaff78 51
rshomberg 12:ea407dcaff78 52 void SegWrite(float val){
rshomberg 12:ea407dcaff78 53 // Convert val to ones and tens char
rshomberg 12:ea407dcaff78 54 ones = fmod(rint(val),10);
rshomberg 12:ea407dcaff78 55 tens = fmod(rint(val) / 10, 10);
rshomberg 12:ea407dcaff78 56
rshomberg 12:ea407dcaff78 57 Seg1 = SegConvert(ones);
rshomberg 12:ea407dcaff78 58 Seg2 = SegConvert(tens);
rshomberg 9:da0b72918880 59 }