// For: https://forum.arduino.cc/t/how-to-use-return-x-in-for-inside-function/1008974/8
void setup()
{
Serial.begin(115200);
}
void loop()
{
unsigned int test = random(0, 32760);
Serial.print( "Testnumber is ");
Serial.print( test);
Serial.print( " (");
for( int i=5; i>=1; i--)
{
Serial.print( GimmeThatDigit( test, i));
if( i>1)
Serial.print( ", ");
}
Serial.print( ")");
Serial.println();
delay( 2000);
}
int GimmeThatDigit( unsigned int number, int digit)
{
unsigned int result; // the resulting decimal number
for( int i=0; i<digit; i++) // digit is the number of the requested digit 1...5
{
result = number % 10;
number /= 10;
}
return result;
}