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);
}
}
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
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.
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);
}
}