3 Digit 7 Segment problem

Hi all,

i am kind of new to arduino. I am currently doing a project regarding on 3x Digit 7 segment.

i need to do a control of speed where the inputs are constantly changing and i have to display it correspondingly.

What i am facing now was. i could not control individual number. ie input number was 100, my display will give me 111. likewise if the number was 123, it will be 111. i am not sure how to code it to retrieve "1" "2" "3" and string them up..

How are the three digits wired up? The usual practice is to connect all like segments together and select which digit to light up by driving the common for that digit.

Please post your code.

Here is a updated codes. from the codes, i can retrieve 0-9 but however when i reach 10, i could not display “1” “0”. And furthermore, LED is either blank or jump into “0"0”

int segA = 13; //Display pin 14
int segB = 12; //Display pin 16
int segC = 11; //Display pin 13
int segD = 10; //Display pin 3
int segE = 9; //Display pin 5
int segF = 8; //Display pin 11
int segG = 7; //Display pin 15

int digit1 = 6; //Display 1 pin 12 SCREEN 1 FROM LEFT TO RIGHT
int digit2 = 5; //Display 1 pin 9 SCREEN 2 FROM LEFT TO RIGHT
int digit3 = 4; //Display 1 pin 8 SCREEN 3 FROM LEFT TO RIGHT
int y;
int pincount;
int num = 10;
int ten;

void setup()
{
pinMode(segA, OUTPUT);
pinMode(segB, OUTPUT);
pinMode(segC, OUTPUT);
pinMode(segD, OUTPUT);
pinMode(segE, OUTPUT);
pinMode(segF, OUTPUT);
pinMode(segG, OUTPUT);

pinMode(digit1, OUTPUT);
pinMode(digit2, OUTPUT);
pinMode(digit3, OUTPUT);
}

void displayNumber()
{
int y;

for ( pincount == 0; pincount < 200; pincount++)
{
if ( pincount == num)
{
y = pincount;
} else
{

}

switch (y)
{
case 0:
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, LOW);
break;

case 1:
digitalWrite(segA, LOW);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
break;

case 2:
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, LOW);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, LOW);
digitalWrite(segG, HIGH);
break;

case 3:
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, HIGH);
break;

case 4:
digitalWrite(segA, LOW);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;

case 5:
digitalWrite(segA, HIGH);
digitalWrite(segB, LOW);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;

case 6:
digitalWrite(segA, HIGH);
digitalWrite(segB, LOW);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;

case 7:
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
break;

case 8:
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;

case 9:
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;
}
}
}

void loop() {

{
// int num = 2;
int x, y;

if (num >= 100)
{
x = 3;
} else if (num < 10)
{
x = 1;
} else
{
x = 2;
}
switch (x)
{
case 1:
digitalWrite(digit1, HIGH);
digitalWrite(digit2, HIGH);
digitalWrite(digit3, LOW);
displayNumber();
break;
// LOW is all light up
case 2:
digitalWrite(digit1, HIGH);
digitalWrite(digit2, LOW);
digitalWrite(digit3, LOW);
displayNumber();
break;

case 3:
digitalWrite(digit1, LOW);
digitalWrite(digit2, LOW);
digitalWrite(digit3, LOW);
displayNumber();
break;
}
}

}

A quick glance:

At the end of your listing;

{
      digitalWrite(digit1, LOW);
      y == 2;
      digitalWrite(digit2, LOW);
      y == 0;
      digitalWrite(digit3, LOW);
     // y == 0;
    }
      break;
    }
}

The two statements y == 2; y == 0: are not ASSIGNMENT statements, they are COMPARISON statements, and in this case do nothing. (same for the commented third one)

I don't see where the displayNumber() function is ever called.

To extract individual digits of a 3 digit number I usually use modulo division

Basically i am testing on the ones and tens, the 3rd branch was just edited and try it out and i pasted it without knowing… i am sorry about it

Here is the method I use for extracting the digits from a 3 digit number, it may not be the most elegant or shortest but it will get you there.

byte digits[3];            // declare a 3 byte array
int num = 793;             // as an example
digits[2] = num/100;       // digits[2] now holds 7
digits[0] = num % 10;      // digits[0] now holds 3
digits[1] = num % 100;     // digits[1] now holds 93
digits[1] = digits[1] /10; // digits[1] now holds 9

// The digits array now holds each digit of num in its elements.
// digits[2]  is 7
// digits[1]  is 9
// digits[0]  is 3

If you rather not use an array declare your own variables such as: byte ld, md, rd;
for left digit, middle digit and right digit

Thanks for your infor,

Just curious, mupltiplex or shift register method are better suit the program?

Multiplexing requires 8 pins plus one each for each digit, shift registers reduce the pin requirement dramatically. However, both methods require the MCU to constantly refresh the display which can cause flicker problems if the MCU is heavily involved doing other tasks.
The MAX7219 LED decoder/driver gives you both low pin count and no need for refresh software. You can get the chip and hook it up yourself or just go shopping at eBay or Amazon and get a neat little 8 digit stick with the MAX7219 attached, ready to go.