fast and effective

Dependencies:   TMP102 mbed

Committer:
kevinmark13
Date:
Tue Feb 03 18:16:22 2015 +0000
Revision:
0:8f8e9e2597fa
Lab3 Part 2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kevinmark13 0:8f8e9e2597fa 1 /*
kevinmark13 0:8f8e9e2597fa 2 In this part of the Lab 3, you will make a digital thermometer using the SEN-11931 breakout board as well as the 4-bank seven-segment LED display.
kevinmark13 0:8f8e9e2597fa 3
kevinmark13 0:8f8e9e2597fa 4 Study carefully chapter 7 regarding the digital temperature sensor provide in the lab kit, referring to the TMP102 datasheet and SEN-11931
kevinmark13 0:8f8e9e2597fa 5 breakout board schematics (under Weeks 5 & 6 --> Lab 3 Extra Files).
kevinmark13 0:8f8e9e2597fa 6
kevinmark13 0:8f8e9e2597fa 7 Design the hardware connection of the SEN-11931, reusing the connection from part I of the this lab,
kevinmark13 0:8f8e9e2597fa 8 for the mbed to read the temperature from the SEN-11931 and display the temperature in Fahrenheit degrees on the
kevinmark13 0:8f8e9e2597fa 9 LED display in the format of xxx.x. Build your circuit and include all the required information about your hardware design in your lab report.
kevinmark13 0:8f8e9e2597fa 10 You will also need to make the decision on whether pull-up resistors are needed.
kevinmark13 0:8f8e9e2597fa 11
kevinmark13 0:8f8e9e2597fa 12 Based on the hardware you designed, write a code that takes temperature measurement every 5 seconds and display the temperature in
kevinmark13 0:8f8e9e2597fa 13 Fahrenheit degrees on the 4-bank seven-segment LED display.
kevinmark13 0:8f8e9e2597fa 14
kevinmark13 0:8f8e9e2597fa 15 Test your digital thermometer and explain your testing process and how you use your test results to confirm that your digital
kevinmark13 0:8f8e9e2597fa 16 thermometer functions properly.
kevinmark13 0:8f8e9e2597fa 17
kevinmark13 0:8f8e9e2597fa 18 */
kevinmark13 0:8f8e9e2597fa 19 #include "mbed.h"
kevinmark13 0:8f8e9e2597fa 20 #include "TMP102.h"
kevinmark13 0:8f8e9e2597fa 21 #include <iostream>
kevinmark13 0:8f8e9e2597fa 22
kevinmark13 0:8f8e9e2597fa 23 using namespace std;
kevinmark13 0:8f8e9e2597fa 24
kevinmark13 0:8f8e9e2597fa 25 Serial pc(USBTX, USBRX);
kevinmark13 0:8f8e9e2597fa 26
kevinmark13 0:8f8e9e2597fa 27 BusOut digselect(p20, p19, p15, p13);
kevinmark13 0:8f8e9e2597fa 28 // bus from MSB to LSB: digit4, digit3, digit2, digit1
kevinmark13 0:8f8e9e2597fa 29
kevinmark13 0:8f8e9e2597fa 30 BusOut digit(p26, p28, p25, p18, p16, p23, p27, p14);
kevinmark13 0:8f8e9e2597fa 31 // bus from MSB to LSB: dp, g, f, e, d, c, b, a
kevinmark13 0:8f8e9e2597fa 32
kevinmark13 0:8f8e9e2597fa 33
kevinmark13 0:8f8e9e2597fa 34 TMP102 temperature(p9, p10, 0x90); //A0 pin is connected to ground
kevinmark13 0:8f8e9e2597fa 35
kevinmark13 0:8f8e9e2597fa 36 float digit;
kevinmark13 0:8f8e9e2597fa 37 float Ftemp = 0;
kevinmark13 0:8f8e9e2597fa 38 float c;
kevinmark13 0:8f8e9e2597fa 39
kevinmark13 0:8f8e9e2597fa 40 int main()
kevinmark13 0:8f8e9e2597fa 41 {
kevinmark13 0:8f8e9e2597fa 42 c = temperature.read();
kevinmark13 0:8f8e9e2597fa 43
kevinmark13 0:8f8e9e2597fa 44 Ftemp = ( 1.8 * c) + 32;
kevinmark13 0:8f8e9e2597fa 45
kevinmark13 0:8f8e9e2597fa 46 while(1) {
kevinmark13 0:8f8e9e2597fa 47
kevinmark13 0:8f8e9e2597fa 48 digselect = 0x1; // digit 1 Binary: 0 0 0 1
kevinmark13 0:8f8e9e2597fa 49 wait_ms(1);
kevinmark13 0:8f8e9e2597fa 50 digselect = 0x2; //digit 2 Binary: 0 0 1 0
kevinmark13 0:8f8e9e2597fa 51 wait_ms(1);
kevinmark13 0:8f8e9e2597fa 52 digselect = 0x4; //digit 3 Binary: 0 1 0 0
kevinmark13 0:8f8e9e2597fa 53 wait_ms(1);
kevinmark13 0:8f8e9e2597fa 54 digselect = 0x8; //digit 4 Binary: 1 0 0 0
kevinmark13 0:8f8e9e2597fa 55 wait_ms(1);
kevinmark13 0:8f8e9e2597fa 56
kevinmark13 0:8f8e9e2597fa 57
kevinmark13 0:8f8e9e2597fa 58 digit = Ftemp;
kevinmark13 0:8f8e9e2597fa 59 Ftemp.digit();
kevinmark13 0:8f8e9e2597fa 60
kevinmark13 0:8f8e9e2597fa 61 wait(1);
kevinmark13 0:8f8e9e2597fa 62 printf( "Temperature: %f\n", Ftemp );
kevinmark13 0:8f8e9e2597fa 63
kevinmark13 0:8f8e9e2597fa 64
kevinmark13 0:8f8e9e2597fa 65 } //end while
kevinmark13 0:8f8e9e2597fa 66
kevinmark13 0:8f8e9e2597fa 67
kevinmark13 0:8f8e9e2597fa 68 } //end main