converting a 0 to 000 for bluetooth transmit

I am working on a project where I would like to turn a potentiometer on one arduino, and receive the RGB information on a second through bluetooth.

Since the PWM would work off of 0-255 integers I need to transmit the current value in 255255255 format. The state is sent through serial and then captured and stored in an Array on the LED arduino. So when transmitting I need to send in the full three digit count across the serial line. If I were only using the blue led, the counts would be 0,0,255, but i need to convert the 0's to 000000255, or 10,10,255 to 010010255, etc.

Output each digit in turn?

void threedigits (byte val)
{
  onedigit (val / 100) ;
  onedigit (val / 10) ;
  onedigit (val) ;
}

void onedigit (byte val)
{
  Serial.print (val % 10) ;
}

Or look at sprintf and the %d format specifier - in this case %03d. Sprintf is going to be more expensive in terms of flash consumed if this is all you use it for though.

Thanks Mark,

I tried this:

void threedigits (byte val)
{
  onedigit (val / 100) ;
  onedigit (val / 10) ;
  onedigit (val) ;
}

void onedigit (byte val)
{
  
  int darray[3]={val % 10} ;
}
}

It compiles just fine, but when i try to pull the data out of the d array it gives me this error "'darray' was not declared in this scope"

Is it possible to pull the data out of this array somehow or do I have to do my bluetooth print from inside the array itself?

Hello Mark,
Big thank you, figured out how to implement it, works perfectly!!!

Thanks again

void onedigit (byte val)
{
  
  int darray[3]={val % 10} ;
}
}

You have mismatched curly braces. The array should be char.

You need to pass the array into onedigit and the index to use, or have them
global. You'd be better off something like this way:

char darray [3] ;

void threedigits (byte val)
{
  darray [0] = '0' + val / 100 % 10 ;
  darray [1] = '0' + val / 10 % 10 ;
  darray [2] = '0' + val % 10 ;
}

or

char darray [3] ;
int index ;

void threedigits (byte val)
{
  index = 0 ;
  onedigit (val / 100) ;
  onedigit (val / 10) ;
  onedigit (val) ;
}
void onedigit (byte val)
{
  darray [index++] = '0' + val % 10 ;
}

But this is detail - you've got the principle now, use it as appropriate to your sketch.