Can someone help me take any number and convert it so I can send it to a 7-segment display, preferably keeping the decimal point?
I'd like to have a number say x that could equal 26.7, 2,832, .8324, or any number under 4 digits really and have a flexible enough code so that I could take x and send it out to the 7-segment display.
I have a method to convert a single digit number into the form necessary to send to the display and the digits of the display are controlled by shift registers and are wired so that the output of one shift register goes into the input of the next.
Did you try the method I last PM'd you about in the old forum?
I'd go find it & post again, but am being called for dish duty!
Will check in later.
You could add dividing by 10 (if the number was greater than 1 to start) and counting how many divisions it took for the result to be less than 1 to determine where the decimal point was.
There's probably some function I'm not familiar with that can do it cleaner. But I thought it was pretty straight forware.
I don't plan on having it connected to the computer so I can't use the serial port.
I was thinking of using a few if functions to find out how large the number is, but I still need to separate it into digits.
Can you convert an integer into hex?
Then it would basically be
if (x >= 1000){
then convert to single digits possible using the hex format and not worry about the decimal point
}
if (100 <= x < 1000){
then convert to single digits possible using the hex format and somehow figure out a way to overwrite the second to last digit to add the decimal point with it
}
Do two passes of comparisons, one for decimal point, one to find the digits:
If (number >999){ 4 digits, no decimal point} // i.e. 1000-9999
if (number <1000 && number >99){ 3+1 digits} // i.e. 100.x to 999.x
if (number < 100 && number > 9){ 2+2 digits} // i.e 10.xx to 99.xx
if (number < 10 && number >1){ 1+3 digits} // i.e. 1.xxx to 9.xxx
if (number < 1) {0+4 digits} // i.e. .0000 to .9999
Set a flag for the appropriate decimal point placement, say decimal_place = 0 to 4 for the 5 cases above
Next, separate out the digits:
switch (decimal_place){
case 0: // 4 digits to left of decimal
digit3 = 0;
digit2 = 0;
digit1 = 0;
digit0 = 0;
digit3 = int(number/1000); // try this
digit2 = int((number - (digit3 * 1000))/100)
digit1 = int ((number-(digit31000) - (digit2100))/10)
digit0 = int ((number-(digit31000) - (digit2100)-(digit1*10) )
break;
case 1: // 1 decimal point
number = number * 10 // now 4 digits to left of decimal
// repeat the above code
break;
case 2: // 2 decimal points
number = number *100 // now 4 digits to left of decimal
// repeat the code above
break;
case 3:
number = number *1000 // now 4 digits to left of decimal
// repeat the code above
break;
case 4:
number = number *10000 // now 4 digits to left of decimal
// repeat the code above
break;
// now look up the segment info from your array for each digit, bit OR (|) in the decimal point in the right place, shift it out ...
That sounds like it'd work well, but how do I take the the number with the decimal point and add it. I suppose I could use more if statements, but that would be a lot of code.