4 years, 8 months ago.  This question has been closed. Reason: Off Topic

Display Temperature on 2x 7 segment display?

Hi everyone, I'm getting back into things after a long time away so slowly picking coding up again.

I would like to know how to display the data from the TMP102 (returned value is float) so I can display it on 2 x 7 segment displays - tens and units -, rather than use an LCD display. I'm working through chapter 6 (and use modular programming) of the book Applying the ARM mbed and using the SegDisplay.cpp and SegDisplay.h files

Could anyone please offer advice?

Thank you kindly in advance.

Question relating to:

1 Answer

4 years, 8 months ago.

SegDisplay.cpp seems to declare two seven segment LED displays. They are connected through BusOut objects named Seg1 and Seg2.

#include "SegDisplay.h"
BusOut Seg1(p5,p6,p7,p8,p9,p10,p11,p12); // A,B,C,D,E,F,G,DP
BusOut Seg2(p13,p14,p15,p16,p17,p18,p19,p20); // A,B,C,D,E,F,G,DP

Your code should call the SegConvert() methods to set the correct segment patterns.

int main() { // main program

 Seg2 = SegConvert(data2); // call function to convert and output
 Seg1 = SegConvert(data1); // call function to convert and output



So you need to convert the float temperature value into tens and units to display it. Try something like this

float temp_fl;
int temp_int
int main() { // main program

 .. read temp from TMP102 into variable temp_fl

 temp_int = temp_fl; // cast float on int

 // sanity checks
 if (temp_int < 0) temp_int = 0;
 if (temp_int > 99) temp_int = 99;

 Seg2 = SegConvert(temp_int / 10); // call function to convert and output tens
 Seg1 = SegConvert(temp_int % 10); // call function to convert and output units (using the modulo operator %)



Obviously there are many ways to do this and it can be done more efficiently. You could also save pins my multiplexing the LED displays.

Accepted Answer

Hi Wim!! :-) Nice to hear from you again. Id looked into how to convert type float to type int and checks for values above and below the 0.5 region. So it was the splitting into 10's and units I was hung up on and getting the numbers directed to the correct 7 seg display. By the way I've also updated the lcd.h file I can see you've really been busy with it...excellent work.

Thanks for the help I'll develop and use your coding hints.

Regards Degs

posted by Derek Calland 29 Jan 2017