I'm trying to port my code to a different platform:
void displayNumber(int toDisplay)
{
for(int digit = 4 ; digit > 0 ; digit--)
{
//Turn on a digit for a short amount of time
switch(digit)
{
case 1:
control &= ~_BV(0); // CHIP SELECT - DSPIC DATA, SPI
break;
case 2:
control &= ~_BV(1);
break;
case 3:
control &= ~_BV(2);
break;
case 4:
control &= ~_BV(3);
break;
}
//Turn on the right segments for this digit
lightNumber(toDisplay % 10);
toDisplay /= 10;
//Turn off all segments
lightNumber(10);
control = 0b00001111; // Represents which digits to light up. For one display the first 4 bits are used.
}
}
I'm having problems with this part of the loop
lightNumber(toDisplay % 10);
More specifically the modulus function on the line above.
You wrote "I'm trying to port my code to a different platform". So how is anybody supposed to answer "Any way to implement this function manually?" when "this function" refers to an operator (NOT a function!) that is built into C and C++?
If toDisplay is an integer, many languages will allow you to emulate the modulus function by doing the following:
toDisplay - (10*(toDisplay/10))
However, there are some languages where this doesn't work, and it will not work if toDisplay is a real or floating point variable. You have not provided sufficient information to answer the question.
toDisplay /= 10;
is equivalent to
toDisplay = toDisplay/10;
except in some weird corner cases that depend upon the type of toDisplay.
I was being cautious, especially since we are talking about %. But I do know that the C statement parser I used for a graphics program basically made every operator/function a function.