Problem in output. 7 segment single digit display. NEED HELP!

I should type a number from the keyboard and the display should show that one. The hardware is fine but i can't find the problem in the code. When i load the sketch and then i type the number on the serial monitor the display always shows an 8 even i type 0,1,2 or else. datasheet of the display is 5161AS. Can someone help me? the code is below

#include <EEPROM.h>

const int A=7;
const int B=6;
const int C=4;
const int D=2;
const int E=11;
const int F=9;
const int G=10;
int x=0;
int n=0;
bool a;
bool b;
bool c;
bool d;
bool e;
bool f;
bool g;
void setup() {
 pinMode (A,OUTPUT);
 pinMode (B,OUTPUT);
 pinMode (C,OUTPUT);
 pinMode (D,OUTPUT);
 pinMode (E,OUTPUT);
 pinMode (F,OUTPUT);
 pinMode (G,OUTPUT);

Serial.begin(9600);

EEPROM.write(0,63);
EEPROM.write(1,6);
EEPROM.write(2,91);
EEPROM.write(3,79);
EEPROM.write(4,102);
EEPROM.write(5,109);
EEPROM.write(6,125);
EEPROM.write(7,7);
EEPROM.write(8,127);
EEPROM.write(9,103);


}

      void loop() {
  if (Serial.available() > 0) 
  {   
      n=Serial.read()-48;
      x=EEPROM.read(n);
      a=bitRead(x,0);
      digitalWrite(A,a);
      b=bitRead(x,1);
      digitalWrite(B,b);
      c=bitRead(x,2);
      digitalWrite(C,c);
      d=bitRead(x,3);
      digitalWrite(D,d);
      e=bitRead(x,4);
      digitalWrite(E,e);
      f=bitRead(x,5);
      digitalWrite(F,f);
      g=bitRead(x,6);
      digitalWrite(G,g);
          
 }
}
digitalWrite (A, bitRead(x,0));

Have you verified that your EEPROM lookup table has been written correctly?

Please remember to use code tags when posting code

yes the EEPROM should be fine.
Sorry it's my first topic so i don't know how to post it yet :frowning:

I agree, it should be fine, but have you verified it?

Also, what is the line ending of your serial monitor?

yes the lookup table is right.

how can i see the line ending?

It's the control along the bottom of the pane,labelled "Line ending"

ooo i found the problem, anyway thanks for the time ahaha

thank you man :slight_smile:

And the problem was . . ?

that one, it's in italian but "Nessun fine riga" is "no endline".
before was on "A capo(NL)" that means "to head" i think. so was the endline yes, thank you man :slight_smile:

I'm really stupid for not checking that ahah

That's right - the last character your sketch saw would always be newline.
Subtracting 48 from newline give a negative number (-38) which you then used to lookup a blank EEPROM location.
Uninitialised EEPROM contains 0xFF, so all segments lit on your LED display.

yeah that's right! :slight_smile:

do you know a way to turn on one led at a time which form the number?
in a sequence

Have you tried putting a delay between the digitalWrites?

yes i did it by this method, but i don't know how to keep showing the number until the user type a new one, and then change the led's to the second one. Do you have an idea starting from this code?

#include <EEPROM.h>

const int A=7;
const int B=6;
const int C=4;
const int D=2;
const int E=11;
const int F=9;
const int G=10;
int x=0;
int n=0;
void setup() {
 pinMode (A,OUTPUT);
 pinMode (B,OUTPUT);
 pinMode (C,OUTPUT);
 pinMode (D,OUTPUT);
 pinMode (E,OUTPUT);
 pinMode (F,OUTPUT);
 pinMode (G,OUTPUT);

Serial.begin(9600);

EEPROM.write(0,63);
EEPROM.write(1,6);
EEPROM.write(2,91);
EEPROM.write(3,79);
EEPROM.write(4,102);
EEPROM.write(5,109);
EEPROM.write(6,125);
EEPROM.write(7,7);
EEPROM.write(8,127);
EEPROM.write(9,103);


}

void loop() {
  if (Serial.available() > 0) {   
      n=Serial.read()-48;
      x=EEPROM.read(n);
      digitalWrite(A,bitRead(x,0));
      delay(200);
      digitalWrite(A,LOW);
      digitalWrite(B,bitRead(x,1));
      delay(200);
      digitalWrite(B,LOW);
      digitalWrite(C,bitRead(x,2));
      delay(200);
      digitalWrite(C,LOW);
      digitalWrite(D,bitRead(x,3));
      delay(200);
      digitalWrite(D,LOW);
      digitalWrite(E,bitRead(x,4));
      delay(200);
      digitalWrite(E,LOW);
      digitalWrite(F,bitRead(x,5));
      delay(200);
      digitalWrite(F,LOW);
      digitalWrite(G,bitRead(x,6));
      delay(200);
      digitalWrite(G,LOW);
      delay(200);
      }
}

Hint: x still has the same value.

Please remember to use code tags when posting code.

You can stop writing the EEPROM now - the lookup table is already there.

how can i add the tag?

So i need one more variable to to assign it to the second number?

You just click on the pencil icon to edit your post, highlight your code, then click on the "</>" icon

No, I don't think you need another variable; you have both n and x, right up until the time you read in a new character.

so i have to change the value of x?