Arduino uno board

Hi I'm a beginner at programming and have created a board with a seven segment led and a 4x3 keypad but the 7 segment isn't fully lighting up and only partly lights for all number, can someone please help. thanks.

#include <sevenSegmentDisplay.h>
#include <Keypad.h>
const byte cols=3;
const byte rows=4;

char keys[rows][cols]={
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'},
};
byte colspins[cols]={6,7,8};
byte rowspins[rows]={5,4,3,2};

Keypad kpd=Keypad(makeKeymap(keys),rowspins,colspins,rows,cols);

int A=A0;
int B=A1;
int C=11;
int D=12;
int E=13;
int F=A2;
int G=A3;

void one()
{
//active low pins
digitalWrite(A,HIGH);
digitalWrite(B,LOW);
digitalWrite(C,LOW);
digitalWrite(D,HIGH);
digitalWrite(E,HIGH);
digitalWrite(F,HIGH);
digitalWrite(G,HIGH);
digitalWrite(DP,HIGH);
return;
}
void two()
{
//active low pins
digitalWrite(A,LOW);
digitalWrite(B,LOW);
digitalWrite(C,HIGH);
digitalWrite(D,LOW);
digitalWrite(E,LOW);
digitalWrite(F,HIGH);
digitalWrite(G,LOW);
digitalWrite(DP,HIGH);
return;
}
void three()
{
//active low pins
digitalWrite(A,LOW);
digitalWrite(B,LOW);
digitalWrite(C,LOW);
digitalWrite(D,LOW);
digitalWrite(E,HIGH);
digitalWrite(F,HIGH);
digitalWrite(G,LOW);
digitalWrite(DP,HIGH);
return;
}
void four()
{
//active low pins
digitalWrite(A,HIGH);
digitalWrite(B,LOW);
digitalWrite(C,LOW);
digitalWrite(D,HIGH);
digitalWrite(E,HIGH);
digitalWrite(F,LOW);
digitalWrite(G,LOW);
digitalWrite(DP,HIGH);
return;
}
void five()
{
//active low pins
digitalWrite(A,LOW);
digitalWrite(B,HIGH);
digitalWrite(C,LOW);
digitalWrite(D,LOW);
digitalWrite(E,HIGH);
digitalWrite(F,LOW);
digitalWrite(G,LOW);
digitalWrite(DP,HIGH);
return;
}
void six()
{
//active low pins
digitalWrite(A,LOW);
digitalWrite(B,HIGH);
digitalWrite(C,LOW);
digitalWrite(D,LOW);
digitalWrite(E,LOW);
digitalWrite(F,LOW);
digitalWrite(G,LOW);
digitalWrite(DP,HIGH);
return;
}
void seven()
{
//active low pins
digitalWrite(A,LOW);
digitalWrite(B,LOW);
digitalWrite(C,LOW);
digitalWrite(D,HIGH);
digitalWrite(E,HIGH);
digitalWrite(F,HIGH);
digitalWrite(G,HIGH);
digitalWrite(DP,HIGH);
return;
}
void eight()
{
//active low pins
digitalWrite(A,LOW);
digitalWrite(B,LOW);
digitalWrite(C,LOW);
digitalWrite(D,LOW);
digitalWrite(E,LOW);
digitalWrite(F,LOW);
digitalWrite(G,LOW);
digitalWrite(DP,LOW);
return;
}
void nine()
{
//active low pins
digitalWrite(A,LOW);
digitalWrite(B,LOW);
digitalWrite(C,LOW);
digitalWrite(D,HIGH);
digitalWrite(E,HIGH);
digitalWrite(F,LOW);
digitalWrite(G,LOW);
digitalWrite(DP,HIGH);
return;
}
void zero()
{
//active low pins
digitalWrite(A,LOW);
digitalWrite(B,LOW);
digitalWrite(C,LOW);
digitalWrite(D,LOW);
digitalWrite(E,LOW);
digitalWrite(F,LOW);
digitalWrite(G,HIGH);
digitalWrite(DP,HIGH);
return;
}
void setup()
{
Serial.begin(9600);
pinMode(A, OUTPUT);
pinMode(B, OUTPUT);
pinMode(C, OUTPUT);
pinMode(D, OUTPUT);
pinMode(E, OUTPUT);
pinMode(F, OUTPUT);
pinMode(G, OUTPUT);
pinMode(DP, OUTPUT);
}

void loop()
{

char key='\0';
label: key=kpd.getKey();
Serial.println(key);

if(key=='1')
{
one();
goto label;
}
else if(key=='2')
{
two();
goto label;
}
if(key=='3')
{
three();
goto label;
}
else if(key=='4')
{
four();
goto label;
}
else if(key=='5')
{
five();
goto label;
}
if(key=='6')
{
six();
goto label;
}
else if(key=='7')
{
seven();
goto label;
}
else if(key=='8')
{
eight();
goto label;
}
else if(key=='9')
{
nine();
goto label;
}
else if(key=='0')
{
zero();
goto label;
}
else
{
Serial.println(" ");
}
}

Your topic has been moved. Do not post in "Uncategorized"; see the sticly topics in Uncategorized - Arduino Forum.

Please edit your post, select all code and click the <CODE/> button; next save your post. This will make the code easier to read, easier to copy and the forum software will display it correctly.


Are you using current limiting resistors for your LED display? Each segment needs it's own resistor.

1 Like

Hi, @adev524
Welcome to the forum.

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

1 Like

I think you have your 7seg wired incorrectly, and the random segments you see are the backwards-wired segments. Your code points to having a common anode 7seg, with COM wired to Vcc.

To test your 7seg (for anode or cathode):

  1. put a 470 ohm resistor on any segment.
  2. attach a jumper to the resistor.
  3. attach that jumper to ground.
  4. attach another jumper to VCC
  5. touch the VCC jumper to COM.
  6. If the segment lights, you have a COMMON ANODE 7seg.
  7. if the segment does not light...
    7a. remove all jumpers
    7b. connect the COM leg to ground
    7c. connect the resistor with jumper to any leg
    7d. touch the resistor/jumper to VCC
    7e. if the segment lights, you have a COMMON CATHODE 7seg.

Your non-definition and non-configuration of "DP" might cause a problem, although "DP" is defined in sevenSegmentDisplay.h and probably does not need definition (but the library file gives DP a value of 255... I do not know why)... and I could not get the DP to work without defining it, so I defined and configured "dp" to pin DIO 10.

Your sketch starts by turning on all the segments... but you should start with the segments off (all segments HIGH)... make a "clear()" function and call it from "setup()"

void clear()
{
  //active low pins
  digitalWrite(A, HIGH);
  digitalWrite(B, HIGH);
  digitalWrite(C, HIGH);
  digitalWrite(D, HIGH);
  digitalWrite(E, HIGH);
  digitalWrite(F, HIGH);
  digitalWrite(G, HIGH);
  digitalWrite(dp, HIGH);
}

Your "8" has the DP as ON... it should be OFF (dp segment should be HIGH).

Remove all the "else" and "return"- as they are not necessary.

After the edits, your program works. Press a number 0 through 9 and it shows on the 7seg.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.