Getting byte values to appear as decimal.

My current project entails sending bytes over the air from one arduino to another by way of XBee API.

Take for example I wish to send the decimal numbers, 127, 57, and 90.

My transmission turns that into a HEX byte when it sends across 2 xbees. And lands on a second arduino. Stored as a byte.

byte pixel[] = {0x7F, 0x39, 0x5A}

I then plug in this info to a command string. with integers.

 strip.setPixelColor(1, pixelcell[2], pixelcell[1], pixelcell[0]) ;

Which would be all well and good, but the setPixelColor string need decimals. If you send it as is, it uses a HEX counting range. EX : 08 to 09 to 0A, 0B, 0C, 0D, 0E, 0F, 10, 11.

This screws up the setPixelColor, since it is not expecting to see HEX characters. It wants decimal numbers.

I need it to convert the HEX to decimal when it fills in those spaces. It should progress as: 08,09,10,11,12,13

Now in a normal Serial.println. You can easily convert a number to a decimal by simply adding DEC to the end.

Example:

Serial.println(pixelcell[1], DEC); and you would get: 57.

How can I do this when it is not printing to Serial in ascii form?

I have tried wrapping it in a char() but that still outputs as a HEX. Example: char(pixelcell[2]) = 7F.

Do you have a suggestion on how I could address this problem?

[ SOLVED ] - Cause: Miss understanding of the byte protocol used by LPD6803 LED's

Thank you Delta_G.

What you posted does make sense. And should work.

I did figure out that my setPixelColor only looks at the lower 5 bits of a byte.

In HEX DEC = Binary
0x00 00 = 0000 0000
0x01 01 = 0000 0001
0x0E 30 = 0001 1110
0x0F 31 = 0001 1111
0x10 32 = 0010 0000
0x11 33 = 0010 0001

So the setPixelColor sees 01 and 33 as the same xxx0 0001.

As of right now, the value being input'd is between 0 and 255. I was dividing it down by 2. cause I thought the range for LPD6803 LED's were 0 thru 127. But now that I see that it's true range is 0 thru 31. I need to divide by 8. So I would be converting 0 thru 255, down to a range of 0 thru 31.

As you mentioned Delta_G. The computer doesn't really care what format the data is stored in. And neither did mine. I just thought it was sending out info in the wrong order. But looking at it from the raw binary side. I see where my miss understanding was.

[ SOLVED ]

1 Like