0

I’ve bought this shield . I’m looking for a way to display decimal point, without using any a designated library. Most examples as this one shows only 0-9.

EDIT1 update link Link

3
  • this display requires frequent refresh else it looks like it shows only one number – Juraj Sep 1 '20 at 14:47
  • 1
    Does this answer your question? delay() problem for 74HC595 and 7-segment – Juraj Sep 1 '20 at 14:49
  • The link to the example is dead. The decimal point is just like any other segment on the display. Set the corresponding output pin of the 75HC595 shift register to high or low (depending on the way, that the display is wired). – chrisl Sep 1 '20 at 17:06
1

So if you click your 2nd link, it includes sample code for various sections of the multi-function shield.

One of them is titled "segment display".

If you look at that code, line 7 defines the bit patterns for each of the digits from 0 to 9:

const byte SEGMENT_MAP[] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0X80,0X90};

If you map them out in binary, you get:

0xC0,   1100 0000   0
0xF9,   1111 1001   1
0xA4,   1010 0100   2
0xB0,   1011 0000   3
0x99,   1001 1001   4
0x92,   1001 0010   5
0x82,   1000 0010   6
0xF8,   1111 1000   7
0X80,   1000 0000   8
0X90    1001 0000   9

A 0 character has all the segments lit except the middle "cross-bar". An 8 character has ALL of the segments lit. But the bit pattern for 8 is 1000 0000. That suggests that a 0 bit means a segment is lit, and 1 means it is off. Since the highest order bit of all of those characters is 1 (off) it suggests that the high-order bit is the decimal place bit. (It's the only bit that never changes.)

So if you replace

const byte SEGMENT_MAP[] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0X80,0X90};

with

const byte SEGMENT_MAP[] = {0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0X00,0X10};

You should get all the digits drawn with their corresponding decimal place lit.

I'd try that first to verify that I'm correct.

I'd then suggest writing code that reads the segments value for each digit, decides if you want a decimal place at that position, and if so, doing a bitwise AND (& in C/C++) on the value with 0X7F to clear the decimal bit for that character. (Remember it looks like a 0 means a given LED segment should be lit.

You could modify the function WriteNumberToSegment() to take a "lightDot" parameter, and have it change the bit if you pass TRUE (1):

void WriteNumberToSegment(byte Segment, byte Value, bool lightDot)
{
    digitalWrite(LATCH_DIO,LOW);
    bool bits = SEGMENT_MAP[Value]);
    if (lightDot) { 
       bits &= 0x7F; //To light the decimal for this digit, clear the 0x80 bit
    }
    shiftOut(DATA_DIO, CLK_DIO, MSBFIRST, bits);
    shiftOut(DATA_DIO, CLK_DIO, MSBFIRST, SEGMENT_SELECT[Segment] );
    digitalWrite(LATCH_DIO,HIGH);
}

(I don't remember for sure if bool is a valid type in Arduino C/C++. If not, just replace bool with uint8 in the above.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.