7 Segment Display not working right

#include <Keypad.h>
#include <Servo.h>
char P1='1';char P2='2';char P3='3';char P4='A'; 
char C1, C2, C3, C4; 


int roteLED = 12;
int grueneLED = 13; 

const byte COLS = 4;
const byte ROWS = 4; 
int z1=0, z2, z3, z4; 

char hexaKeys[ROWS][COLS]={
{'D','#','0','*'},
{'C','9','8','7'},
{'B','6','5','4'},
{'A','3','2','1'}
};

byte colPins[COLS] = {2,3,4,5}; 
byte rowPins[ROWS] = {6,7,8,9}; 
char Taste; 
Keypad Tastenfeld = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 

#include "SevSeg.h" 
SevSeg sevseg; 





//RFID

#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 53
#define RST_PIN 10
MFRC522 mfrc522(SS_PIN, RST_PIN);


void setup() 
{

byte numDigits = 4;
byte digitPins[] = {28, 29, 30, 31}; 
byte segmentPins[] = {32, 33, 34, 35, 36, 37, 38, 39}; 
sevseg.begin(COMMON_CATHODE, numDigits, digitPins, segmentPins); 

pinMode(roteLED, OUTPUT); 
pinMode(grueneLED, OUTPUT);
//RFID
SPI.begin();
mfrc522.PCD_Init();

}

void loop() 
{


Anfang: 
Taste = Tastenfeld.getKey(); 
if (Taste) 

 {
  Serial.println(Taste);
  sevseg.refreshDisplay();
  sevseg.setNumber(1111);
 if (Taste=='*') 
   {
   Serial.println("Tuer verriegelt");
   delay(3000);
 
   digitalWrite(roteLED, HIGH); 
   digitalWrite(grueneLED, LOW); 
   z1=0; z2=1; z3=1; z4=1;
   goto Anfang; 
   }
   
  if (Taste=='#') 
   {
   if (C1==P1&&C2==P2&&C3==P3&&C4==P4) 
   {
   Serial.println ("Code korrekt, Schloss offen");
   servoblau.write(0); 
   digitalWrite(roteLED, LOW); 
   digitalWrite(grueneLED, HIGH); 
   
   }
   else 
   {
   Serial.println ("Code falsch, Schloss gesperrt");
   digitalWrite(roteLED, HIGH); 
   digitalWrite(grueneLED, LOW); 
   delay(3000);
   z1=0; z2=1; z3=1; z4=1;
   goto Anfang; 
   }
  }

  if (z1==0) 
  {
  C1=Taste; 
  Serial.print("Die Taste "); 
  Serial.print(C1);
  Serial.println(" wurde gedrueckt");
  z1=1; z2=0; z3=1; z4=1; 
  goto Anfang;
  }
 
  if (z2==0) 
  {
  C2=Taste; 
  Serial.print("Die Taste "); 
  Serial.print(C2);
  Serial.println(" wurde gedrueckt");
  z1=1; z2=1; z3=0; z4=1; 
  goto Anfang;
  }

  if (z3==0) 
  {
  C3=Taste; 
  Serial.print("Die Taste ");
  Serial.print(C3);
  Serial.println(" wurde gedrueckt");
  z1=1; z2=1; z3=1; z4=0; 
  goto Anfang;
  }
  
  if (z4==0) 
  {
  C4=Taste; 
  Serial.print("Die Taste "); 
  Serial.print(C4);
  Serial.println(" wurde gedrueckt");
  z1=1; z2=1; z3=1; z4=1;
  }
 }
//RFID

  if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}

if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}

long code=0;

for (byte i = 0; i < mfrc522.uid.size; i++)
{
code=((code+mfrc522.uid.uidByte[i])*10);
}

Serial.print("Die Kartennummer lautet:");

Serial.println(code);


if (code==639810) { 

Serial.println ("Code korrekt, Schloss offen");
   
   digitalWrite(roteLED, LOW); 
   digitalWrite(grueneLED, HIGH);
   delay(5000);
   Serial.println("Tuer verriegelt");
   delay(3000);
   digitalWrite(roteLED, HIGH); 
   digitalWrite(grueneLED, LOW);
   z1=0; z2=1; z3=1; z4=1; 
   goto Anfang; 

  }
  if (code==1531190) { 

Serial.println ("Code korrekt, Schloss offen");
   
   digitalWrite(roteLED, LOW); 
   digitalWrite(grueneLED, HIGH);
   delay(5000);
   Serial.println("Tuer verriegelt");
   delay(3000);
   digitalWrite(roteLED, HIGH); 
   digitalWrite(grueneLED, LOW); 
   z1=0; z2=1; z3=1; z4=1; 
   goto Anfang;

  }
}

My 7 segment display isn’t working the way it should.
I’m building a keypad, which eventualy should open a door and the code entered in the keypad should be shown in the display. In this code, I’ve just got a little test. It should show 1111 on the display if a key was pressed. Unfortionatly, the display shows anything, but not 1111 (no numbers, just some weired stuff). I’ve tried to run the display with another simple code, where it should only show 1234 with nothing else in the code. That one worked fine.

I’m new to Arduino and got most of the stuff from funduino.
(Sorry for my english btw.)

(Code tags added by Moderator.)

Your topic has been moved here as this forum section is more appropriate than where it was originally posted.

Please take care to post in the correct forum section

The easier you make it to read and copy the code the more likely it is that you will get help

Please follow the advice given in the link below when posting code

void setup()
{
  byte numDigits = 4;
  byte digitPins = {28, 29, 30, 31};
  byte segmentPins = {32, 33, 34, 35, 36, 37, 38, 39};
  sevseg.begin(COMMON_CATHODE, numDigits, digitPins, segmentPins);

My guess is that the ‘sevseg’ object just keeps pointers to your pin arrays. Your arrays are local to setup() so they stop existing when setup() is done. Try making them global:

byte numDigits = 4;
byte digitPins = {28, 29, 30, 31};
byte segmentPins = {32, 33, 34, 35, 36, 37, 38, 39};

void setup()
{
  sevseg.begin(COMMON_CATHODE, numDigits, digitPins, segmentPins);

Hi,
unfortionatly that didn’t fixed it for me. It’s very weired. The diplay keeps (only sometimes when i press a button) showing 1 segment of a number.

Post a schematic as wired, not a frizzy thing so we can validate that it is wired correctly.

Where do you call sevseg.refreshDisplay()? I don’t see it anywhere. You should probably put it right after the label “Anfang:” so it is part of your loop.

You know, instead of “goto Anfang;” you could use ‘return;’ to get back to the top of loop().

Can you recomment a software for an Arduino Mega? I’ve tried a couple of softwares now, but some don’t have a mega and with others I can’t change the ports the display is wired to.

Originaly, it was in the first if loop (if Taste). I’ve now put it directly under Anfang, and the display is doing something weired. It gets through the segments of the numbers in milliseconds, but only shows one segment at the time.

Hi, @flexhardt
Welcome to the forum.

Have you compared the simple code you used with the malfunctioning code.

Did you write your code in stages?
You should have code you used to build your project that performed correctly before the bug occurred.

Tom… :grinning: :+1: :coffee: :australia:

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