I built a interface display that consist of 4x 7 segment displays so I can display number from 0 to 9999.
I'm making the code to display a int number in the display and I got it working but Im pretty sure that there are simpler ways of doing it. I was searching on internet about some type of a number mask so to pick each digit in a integer number and store that into new integers (each new integer being a single number digit).
Where DSP is the original integer from 0 to 9999 and d1,d2,d3,d4 are integers representing each digit on the display. When d1=10 (or d2,d3,d4) nothing is displayed on the 7 segment display. When d1=3 means that number 3 will be displayed on the 3rd segment display and so on.
Im going to display floats also (they are really 8segment, 7 ususal and the period).
Any clues on how to simplify this code using masks ?
I built a interface display that consist of 4x 7 segment displays so I can display number from 0 to 9999.
I'm making the code to display a int number in the display and I got it working but Im pretty sure that there are simpler ways of doing it. I was searching on internet about some type of a number mask so to pick each digit in a integer number and store that into new integers (each new integer being a single number digit).
print(seven_seg_digit_0, ((uint16_t) value / 1000) % 10);
print(seven_seg_digit_1, ((uint16_t) value / 100) % 10);
print(seven_seg_digit_2, ((uint16_t) value / 10) % 10);
print(seven_seg_digit_3, ((uint16_t) value / 1) % 10);
if (v != 0)
{
d[3-i] = v % 10;
}
else
{
d[3-i]= 10;
}
and that means that the digit is set to 10 if "v" is 0, in all other cases the digit holds the rest of a division of "v" by 10.
The algorithm is explained easily: Check if the whole value is 0, if yes set the display to "___0" and return (if I don't check that the display is empty in this special case).
Then I handle digits backwards. The last digit is the value mod 10. The the value is divided by 10. Next round (the tens) I do the same, the digits is the current value (hold all tens) mod 10. As soon as I reach 0 I fill the rest of the digits with spaces.