Bin to Hex conversion

smssms

New Member
I'm using a tiny 4D Systems OLED screen and I want a drawn box to change size in proportional to a variable.

To draw a box you define it as ($box, $top left X, $top left Y, $bottom right X, $bottom right Y, $colour) all as HEX constants and then send it to the screen via SEROUT.

So how do I get a variable into the string above as a hexadecimal constant?

If I put $ in front of it, it just convert the name of the variable to hex.
The nearest I got was getting it to accept a variable where it expected to see an ASCII constant by putting # in front of the variable.

Thanks.
 

nick12ab

Senior Member
Bin to hex conversion?

They're stored the same way - it's just how they are displayed. Is what you mean is bin to bcd conversion? In which case use the bintobcd operand in a mathematical statement e.g. let b2 = bintobcd b1.

It always helps to post links to datasheets - I think there's more than just one 4D Systems OLED.
 

smssms

New Member
Page 34 of the manual here specifically covers the rectangle drawing: http://www.4dsystems.com.au/downloads/Semiconductors/GOLDELOX-SGC/Docs/GOLDELOX-SGC-COMMANDS-SIS-rev6.pdf

The more general guide is here: http://www.4dsystems.com.au/downloads/Serial-Display-Modules/uOLED-96-G1(SGC)/Docs/uOLED-96-G1SGC-DS-rev6.pdf

From what I have seen and tried, each statement must be in the "$xx" format (except for specific ASCII strings) so you cannot put a variable in there.

I'll have a look at the bintobcd and see if that helps...

Below is what I want i.e. the rectangle to change width with variable b1

Code:
SEROUT A.1, T2400, ($72,[COLOR="#EE82EE"]b1[/COLOR],$01,$5E,$8,$00,$00)
PAUSE 15
 
Last edited:

PaulRB

Senior Member
Reading that manual page, sounds to me like your example above is the way to go. Except you have put b1 as the top-left x coordinate. If you want b1 to control the width, you need to add the top-left x coordinate to b1 first, then put b1 as the third value after $72. But you don't need to put $, # or anything else in front of b1.
 

westaust55

Moderator
Try a search of the PICAXE forum for example code for the 4-D Systems OLED displays.
Thread heading is something like:
"Getting started with 4D Systems OLED displays"

There I have included code for the PICACE

You just need to send a value - do not put the hash (#) symbol in front of the variable as you want a binary/Hexadecimal value in a single byte, not an ASCII encoded value over several bytes.
 

westaust55

Moderator
Thanks nick.
It is unfortunately (for me at least) slow and cumbersome to try searching the forum from an iPhone.
Often leave until later to add a link if/when I get to a PC.

There is a potential side benefit also in suggesting the "try and search" as some folks do ask questions without first trying to search.
Either through ignorance of what may be there or taking the line that it is easier to ask the same question again even if in some cases it is still current on the first page of the forum.
 
Last edited:

smssms

New Member
Thanks nick.
There is a potential side benefit also in suggesting the "try and search" as some folks do ask questions without first trying to search.
Either through ignorance of what may be there or taking the line that it is easier to ask the same question again even if in some cases it is still current on the first page of the forum.
I do it just to annoy you - it gives my life an extra little bit of meaning....;)

As It happens I have read your articles on the 4D displays before, they were a lot of help.

I did try just putting the variable 'name' in the right position, but it did not draw what I wanted/expected; hence my question on here. I'll re-visit and have a play.

Thanks.
 
Last edited:

westaust55

Moderator
Can you post your program code.
That will likely give folks here a better idea on where things are going wrong and be better able to guide you.
I have written code for an analogue thermometer where the "mercury" would rise and fall using variables to adjust the side of the different coloured rectangles so the ability exists.
 

boriz

Senior Member
With respect to your original question. Numbers (data) are not transmitted in Hex, or Dec, only in Binary. It's a common mistake. These systems are used only for the sake of human readability and have no effect on what is actually transmitted. EG:

Code:
b1=0x72
b1=$72
b1=114
b1=%01110010
Are all identical as far as the Picaxe is concerned. And:

Code:
SEROUT A.1, T2400, ($72)
SEROUT A.1, T2400, (114)
SEROUT A.1, T2400, (%01110010)
SEROUT A.1, T2400, ("r")
SEROUT A.1, T2400, (b1)
All send an identical data stream (when b1=114). But:

Code:
SEROUT A.1, T2400, (#b1)
Is a special case. The # is a macro instruction to the interpreter. From the manual: The # symbol allows ASCII output. Therefore #b1, when b1 contains the data
126, will output the ASCII characters “1” ”2” ”6” rather than the raw data 126.
 
Top