Trying to write a clock that uses only one seven segment LED (you know, for fun), so I am trying to do a conversion from an integer supplied by minute() (from the Time library) into an array of single digits. For instance, to convert, say 42 into an array that is like myminute[3]={'4','2'} or even better into int myminute[3]={4,2}.
I thought I had read the itoa manual correctly thinking that itoa(minute(),myminute,3) would yield the desired affect, but not!
So, a little prodding for this old, balding perl programmer would be helpful.
For a clock using seven segment digits you really don't need or want ascii.
What you really want is the individual digits.
Then you can use the digits to index into a table that has the information
about which segments to turn on for that digit.
Or if you are using one of the 7 segment libraries out there, they also typically
want the digit value (not ascii) that is to be displayed on the 7 segment display which in turn they
use to look up which segments to turn on for that digit.
To get the digits from a 2 digit value like hours/min/seconds
you can use some simple divide by 10 and module by 10 similar
to what gardner showed only skipt converting the digit to ascii.
i.e.
tensdigit = value / 10;
onesdigit = value % 10;
The challenging part when only using a single LED digit for display
(vs 4 or 6 digits)
will be to figure out the cadence/spacing/delay/blinking between displaying digits
so you can tell the fields apart.
i.e. when you see the digit changing, how do you know which digits are hours vs mins etc...
bperrybap:
Ok.... but I've not ever seen a clock that needs to display a number larger than 59 for minutes
Back to the initial ascii question.
Why would you want to have ascii digits when pushing time/clock digits to a seven segment display?
I posted that because there are other uses for extracting digits from a value. Of course a clock only needs 2!
For the clock app, if I were doing it I would make an 10 byte x 7 bit array of segment patterns 0 thru 9 and use the extracted values as an index into the array, then use that data to light the proper segments.