Sparkfun 7 segment display: turning decimals on and off #655
Replies: 6 comments
-
Posted at 2014-11-21 by DrAzzy 56 is the decimal representation of 0b00111000. As binary is base 2, bit 5 is 32, bit 4 is 16, bit 3 is 8 32+16+8=56. You can use both binary and hexadecimal notation (0b.... and 0x... ) in Espruino, as well as decimal. Usually we use whatever format makes the most sense - for example, here, the decimal value is not particularly meaningful - 56? why 56? - but if you look at the binary or hexadecimal form, you can see that it's a byte with bits 3, 4 and 5 as ones. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-11-21 by d0773d Thank you for explaining. I think I understand now :) . Each bit represents the decimals, colon and apostrophe. So, I should send 0b10000000 to only turn on the decimal furthest to the left. Update |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-11-21 by @allObjects The code below may give you what you are looking for. @drazzy explained you the decimal and apostrophe workings (but I'm not sure of your conclusion: To set the decimal point of the first/most left digit, I'd send 0b00000001). Display pH 0...14.4 (theoretically up to 99.4) in 2 digits:
Display temperature 0...999.4### in 3 digits:
Since I do not have the display at hand, I can only test so far as creating the sting to send to it and look at it. In the attachment you find a .html file hat you can download anywhere on your hard drive, open with your browser, and enter value and see the string sent to the display. The .html includes the display pH and display temperature function and a interactive test bed around them (in another post I may add an emulation for the display. For the calculation of the display value I tried to follow what I remembered from my stoichiometry / chemistry classes, where the teacher yelled at us to not consider the error calculation on reading scales, etc... and applied I reversely. You are the scientific judge to that... ;-) For setting the decimal point - and for temperature the apostrophe for degree - I set the 6th (counting from 0) bit always to 1, which brings the character to send into the nicely printable range of either '@abcd' and '`abcd', respectively. If you want to set 'crazy' characters, you have to make a mapping from a character not used otherwise to a binary value. You achieve this by setting up a lookup string for getting an index, and with the index you go and get the binary value. It looks something like that:
The following code will return turn all segments of the first digit on:
You would use the lookup() function to create the string before sending it. Since the module can display all digits and the letters F, P, and H (and more), only for crazy patterns a lookup/mapping is required. Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-11-21 by d0773d @drazzy @allObjects thank you for the explanations Sorry, I'm a bit dyslexic at times :) I meant to write 0b00000001 |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-11-21 by d0773d Everything seems to be functioning quite nicely :-) Now all I need to do is make an object of the functionality and placements of the decimal points. I'll post back in a few days with the code. @allObjects I will for sure read over your post from earlier. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-12-01 by d0773d Code that I threw together to get decimal places to work. It looks a bit rough, but it seems to work.
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2014-11-21 by d0773d
My project consists of espruino, environment sensors and 4 blue 7 segment displays
Datasheet(specifically decimals): https://github.com/sparkfun/Serial7SegmentDisplay/wiki/Special-Commands#decimal
What I would like to accomplish is send data, for an example send the room temp, i.e. 76.7F to the 7-segment display. Depending on where the decimal place is, turn on that decimal which I dont think is that hard to do. What I am struggling with is calculating the bytes to send in order to turn on the specific decimal.
To better understand this i will use the github totorial for my example. For example, To turn on the colon, apostrophe, and far-right decimal point we need to set bits 4, 5, and 3, respectively. Our data byte will therefore be: 0b00111000 (ie. hex 0x38, or decimal 56).
From experience, I know the 0b signifies the data following is in binary format and 00111000 equals 56. Where did the 56 come from? There's a handy chart explaining the bit layout, however I still don't understand.
Beta Was this translation helpful? Give feedback.
All reactions