Electrical – 7 segment led light up specific decimal point

7segmentdisplayarduinoc

I have a 12 pin 7 segment led (ATA8041AB) which is working fine using my code, it just that when I try to light up the decimal point led, it either light up all dp or dont light up at all.

here is my code

int segA = 3; // top
int segB = 4; // right-top
int segC = 5; // right-bottom
int segD = 6; // bottom
int segE = 7; // left-bottom
int segF = 8; // left-top
int segG = 9; // middle
int dp = 10;

int digit1 = 14; // common cathode for digit1 (i.e. sambung A0)
int digit2 = 15; // common cathode for digit2 (i.e. sambung A1)
int digit3 = 16; // common cathode for digit3 (i.e. sambung A2)
int digit4 = 17; // common cathode for digit4 (i.e. sambung A3)


// Number to display
static int number = 0;
static int ms = 0;
String inData; 
int collectedNumber;

int   blinkRate=0;  

//==============================================================//
void setup()
{
    Serial.begin(9600);

    // All pins in digital mode
    pinMode(digit1, OUTPUT);
    pinMode(digit2, OUTPUT);
    pinMode(digit3, OUTPUT);
    pinMode(digit4, OUTPUT);

    pinMode(segA, OUTPUT);
    pinMode(segB, OUTPUT);
    pinMode(segC, OUTPUT);
    pinMode(segD, OUTPUT);
    pinMode(segE, OUTPUT);
    pinMode(segF, OUTPUT);
    pinMode(segG, OUTPUT);
    pinMode(dp, OUTPUT);

}

//==============================================================//
void loop() {

digitalWrite(dp, HIGH);

//as a test, aku letak nilai 9999 display dekat led 

number = 4268;

    digitalWrite(digit1, LOW);
        // light on segments for 'thousands'
        drawDigitFast( (number/1000) % 10 );
        // wait 2 ms
        delay(2);
        // turn off all segments
        drawDigitFast( -1 );
    // turn off cathode for digit1
    digitalWrite(digit1, HIGH);


    digitalWrite(digit2, LOW);
        drawDigitFast( (number/100) % 10 );
        delay(2);
        drawDigitFast( -1 );
    digitalWrite(digit2, HIGH);


    digitalWrite(digit3, LOW);
        drawDigitFast( (number/10) % 10 );
        delay(2);
        drawDigitFast( -1 );
    digitalWrite(digit3, HIGH);


    digitalWrite(digit4, LOW);
        drawDigitFast( number % 10 );
        delay(2);
        drawDigitFast( -1 );
    digitalWrite(digit4, HIGH);

}

//-----------------------------------------------------//
void drawDigitFast(int n)
{
    const byte aPins[8] = {
        segA, segB, segC, segD, segE, segF, segG
    };
    const byte aSegments[11][8] = {
        //  A     B     C     D     E     F     G
        { HIGH, HIGH, HIGH, HIGH, HIGH, HIGH,  LOW }, // 0
        {  LOW, HIGH, HIGH,  LOW,  LOW,  LOW,  LOW }, // 1
        { HIGH, HIGH,  LOW, HIGH, HIGH,  LOW, HIGH }, // 2
        { HIGH, HIGH, HIGH, HIGH,  LOW,  LOW, HIGH }, // 3
        {  LOW, HIGH, HIGH,  LOW,  LOW, HIGH, HIGH }, // 4
        { HIGH,  LOW, HIGH, HIGH,  LOW, HIGH, HIGH }, // 5
        { HIGH,  LOW, HIGH, HIGH, HIGH, HIGH, HIGH }, // 6
        { HIGH, HIGH, HIGH,  LOW,  LOW,  LOW, LOW  }, // 7
        { HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH }, // 8
        { HIGH, HIGH, HIGH, HIGH,  LOW, HIGH, HIGH }, // 9
        {  LOW,  LOW,  LOW,  LOW,  LOW,  LOW,  LOW }  // all off
    };

    if( n < 0 || n > 10 )
    {
        n = 10;
    }

    for( int i = 0; i < 7; i++ )
    {
        digitalWrite( aPins[i], aSegments[n][i] );
    }
}

what I'm trying to write is 4.268, but the best I could do is 4.2.6.8 . can help me please?enter image description here

Best Answer

The fact you enable one at a time is because you need to write each of those sequentially because A-G pins are commons to all of the 4 display, as stated in the datasheet. Guess what, the dp pin too ! So at each digit, the operation :

digitalWrite(digitX, LOW);
   drawDigitFast( (number/10) % 10 );
   delay(2);
   drawDigitFast( -1 );
digitalWrite(digitX, HIGH);

must include the dp operation : digitalWrite(dp, HIGH OR LOW);

The best way should likely to add this operation in your drawDigitFast, including a new bool parameter for your dp value :

void drawDigitFast(int n, bool dpValue)
{
    //....
    digitalWrite(dp, dpValue)
    for( int i = 0; i < 7; i++ )
    {
        digitalWrite( aPins[i], aSegments[n][i] );
    }
}

You can even think about a function auto calculating dp position regarding your value, but I'm a bit lazy to think about implementation.