I am coding a function that prints out any given number on a seven segment display. You call the function like this:
printNumber(12345);
Then the digits are displayed, one after the other, on the display.
To achieve this, the required variable type of said function currently is unsigned long. The problem with that is, that I cannot enter numbers with leading zeros (like 06561).
The easiest solution would be to change the variable type to String. But then, it would be necessary to call the function with quotation marks:
printNumber("013542");
There is no real reason, but this doesn't feel right. I don't want to have quotation marks.
So - is there another possibility? I can provide more code if required.
assuming printNumber(12345); will always take a number less or equal to 5 digits long then something like this may work to print out a number with leading zeros as and when required:
void printNumber(unsigned long number){
for(int i=0; i<5; ++i){
printdigit(number%10); //replace with whatever routine outputs to 7seg display and pass 'number%10' to it
number/=10;
}
}
above will print units digit first, then tens digit, then hundreds digit and so on...