I created this 7 segment that isn’t working properly. I saw a template for this that worked fine but now I can’t seem to find that template. Isn’t a 7 segment just 7 different LED’s? I want the project to just countdown from 9 to 0. The code I copied here is just the setup and what would be needed to start the countdown at 9. I appreicate your guidance!
1. Build the following circuit (Fig-1). For simplicity, instead of placing eight current-limiting resistors on the individual segment lines, a single resistor is placed on the common-cathode (CC) line.
In a practical circuit, however, each segment should have its own current-limiting resistor to ensure uniform brightness across all segments of the display.
2. Convert the following flow chart (Fig-2) into Arduino codes to count from0 to F by repeatedly pressing the UP button. Do not forgt to take care of the bouncing of the button.
byte lupTable[] =
{
0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, //01234567
0x7F, 0x6F, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71 //89ABCDEF
};
byte value = 0;
void setup()
{
//--- set directions of the IO lines----
for(int i = 6; i < 14; i++)
{
pinMode(i, OUTPUT);
}
pinMode(4, INPUT); //UP Button
show(value); //show: 0 iitially
}
void loop()
{
int upBtn = digitalRead(4);
if(uptn == HIGH) //UP button is pressed
{
delay(30); //debouncing delay
value ++; //show: 1, 2, 3, ...... F
show(value);
if(value == 0x0F)
{
while(true); //wait for ever or implent DN function
}
}
}
void show(byte n)
{
byte y = lupTable[n]; //et cc-code from LUT
PORTB = y;
digitalWrite(6, bitRead(y, 6));
}
3. Now, modify sketch of Step-2 to count down from F to 0 when DN button is repeatedly pressed. Do not forgt to take care of the bouncing of the button.
Thank you so much for your reply. I”ve also tried it with resistors in this position without luck. I have pin 9 set as an output. What else should I try? Once I get the 9 to show up, I’ll add the rest counting down.
With a single resistor on the common pin, only the total digit current is limited, not the current of each individual segment. When multiple segments are lit, that total current splits according to each LED’s forward voltage. Because forward voltage varies between segments and changes with temperature, the current distribution becomes unequal. One segment can run brighter and hotter while others are dimmer.
This causes brightness imbalance and can overstress a segment (if one segment has slightly lower forward voltage, it will conduct more current and as it heats, its forward voltage decreases further, increasing current again) even though the overall current is within limits.
I think it's best to use one resistor per segment ensures controlled, predictable current in each LED branch.
You do not have pin 9 connected to anything, it does not matter whether it is set to input or output.
Almost sounds like you have the mistaken idea that setting output on pin 9 will cause a 9 to show on the display. That is completely wrong. Each segment on the display is a single LED. You get a 9 by lighting the individual segments to form the 9.
Thank you all for your wonderful input and also technical details to solve the problem. For this project, I wanted a simple 7 segment without a button. I will teach the 7 segment first and then challenge them to extend their skills by adding a button or other component. The videos I’ve watched online all show similar wiring and code to mine but it doesn’t work for me. I’ve switched the resistors back to using one per segment since this practice is much more accurate. I will take time later to read through the advice and schematics applied and revert. All additional advice is always welcome!
The 9 I refer to in my comments is the number 9 showing on the 7 segment, using 6 of the 7 segments to light this up. I do know that I have not used pin 9 on the Arduino.
I am not sure but I believe I have common cathode. For reference, I have tried to run a ground on both ends of the 7 segment without any difference in the circuit.
If you are using the circuit with a resistor for each segment, does each individual segment light up if you connect its resistor directly to 5V instead of to the arduino pin?