I'm an Arduino newbie having problems with 4 digit 7 segments display. I want to display some thousands to 4 digit 7 segments display but it display only 0000. I want to receive data from serial with string. And display the data to 4 digit 7 segments display... So test make String = '2575'... but it's not work. What's wrong in my codes? Any suggestions here will be a great help. thanks
int segments[] = {A0, A1, A2, A3};
byte digits[10][7] =
{
{ 1,1,1,1,1,1,0 }, // 0
{ 0,1,1,0,0,0,0 }, // 1
{ 1,1,0,1,1,0,1 }, // 2
{ 1,1,1,1,0,0,1 }, // 3
{ 0,1,1,0,0,1,1 }, // 4
{ 1,0,1,1,0,1,1 }, // 5
{ 1,0,1,1,1,1,1 }, // 6
{ 1,1,1,0,0,0,0 }, // 7
{ 1,1,1,1,1,1,1 }, // 8
{ 1,1,1,0,0,1,1 } // 9
};
void setup() {
Serial.begin(9600);
for(int i=2;i<10; i++) {
pinMode(i, OUTPUT);
}
for(int i=0; i<4; i++) {
pinMode(segments[i], OUTPUT);
}
}
void loop() {
String IncomingData = "2575";
for(int i=0; i<4; i++) {
digitalWrite(segments[i], LOW);
int digit = atoi(IncomingData[i]);
displayDigit(digit);
delay(5);
digitalWrite(segments[i], HIGH);
}
}
void displayDigit(int num){
int pin = 2;
for(int i=0;i<7;i++){
digitalWrite(pin+i, digits[num][i]);
}
}
displayDigit(digit);todisplayDigit(3);to see if the problem is in the string parsing, or in the led-displaying part.