Serial communication to display integer on 3digit 7segment display

Hello fellow arduino programmers. I am in a bit of a probelm! would really appreciate your input :slight_smile:

I am having some issues programming a part of my project. What I am trying to do is to display 3digit integer value on a 3digit 7segment display. The hardware for the display uses a 3 digit 7 segment display interface via a 74hc595 8bit serial in parallel out shift register. The hardware works perfectly fine when it is used to display the temperature using a temperature sensor (lm335z) so I am pretty sure everything is working on the hardware side of things. The routine to convert ascii characters sent from the serial monitor to the arduino, to integers works fine separately as well. I can send for example 125 and see I have received 125 as an integer on the serial monitor(not 1(newline) 2(newline) ). How ever when the whole routine is combined to display what I send from the computer via the serial monitor to the display weird things happen. If I send in a 3 digit number say 123, the display only displays the 3. If I input a 2 for example the last digit lights up as 2, but for 3 the second digit lights up to give a zero, for 4 the 1st digit lights up to give a 0 and then after I have gone through 2 numbers successively (any random single digit number) after the initial display , on the 3rd input of a single digit number the last digit on the seven segment display lights up again.
Any help from you experienced users will be greatly appreciated.
Thanks in advance for your suggestions.
I am posting my code as well.

const int digitPins[3] = {
5,6,7}; //4 common anode pins of the display
const int clockPin = 11; //74HC595 Pin 11
const int latchPin = 12; //74HC595 Pin 12
const int dataPin = 13; //74HC595 Pin 14
const int tempPin = A0; //temperature sensor pin
const byte digit[10] = //seven segment digits in bits
{
B00111111, //0
B00000110, //1
B01011011, //2
B01001111, //3
B01100110, //4
B01101101, //5
B01111101, //6
B00000111, //7
B01111111, //8
B01101111 //9
};
int digitBuffer[3] = {
0};
int digitScan = 0;
unsigned int desiredValue = 0;//desiredValue input from the computer using serial monitor
char incomingByte;

void setup(){
Serial.begin(9600);

for(int i=0;i<3;i++)
{
pinMode(digitPins*,OUTPUT);*

  • }*
  • pinMode(tempPin, INPUT);*
  • pinMode(latchPin, OUTPUT);*
  • pinMode(clockPin, OUTPUT);*
  • pinMode(dataPin, OUTPUT); *
  • pinMode(tempPin, INPUT);*
    }

//writes the desiredValue on display
void updateDisp(){

  • for(byte j=0; j<3; j++) *

  • digitalWrite(digitPins[j], LOW);*

  • digitalWrite(latchPin, LOW); *

  • shiftOut(dataPin, clockPin, MSBFIRST, B11111111);*

  • digitalWrite(latchPin, HIGH);*

  • delayMicroseconds(100);*

  • digitalWrite(digitPins[digitScan], HIGH);*

  • digitalWrite(latchPin, LOW); *

  • shiftOut(dataPin, clockPin, MSBFIRST, ~digit[digitBuffer[digitScan]]);*

  • digitalWrite(latchPin, HIGH);*

  • digitScan++;*

  • if(digitScan>2) digitScan=0;*
    }

void loop(){

  • if (Serial.available() > 0) { // something came across serial*

  • desiredValue = 0; // throw away previous integerValue*

  • while(1) { // force into a loop until 'n' is received*

  • incomingByte = Serial.read();*

  • if (incomingByte == '\n') break; // exit the while(1), we're done receiving*

  • if (incomingByte == -1) continue; // if no characters are in the buffer read() returns -1*
    _ desiredValue *= 10; // shift left 1 decimal place_

  • // convert ASCII to integer, add, and shift left 1 decimal place*

  • desiredValue = ((incomingByte - 48) + desiredValue);*

  • Serial.println(desiredValue);*

  • digitBuffer[2] = int(desiredValue)/100;*

  • digitBuffer[1] = (int(desiredValue)%100)/10;*

  • digitBuffer[0] = (int(desiredValue)%10);*

  • updateDisp();*

  • delay(2);*
    }
    }
    }

Does your code REALLY look like that? I seriously doubt it. Now, go read the sticky at the top of the forum that you were supposed to read before posting in this section, and try again.

And, before you post that code again, use Tools + Auto Format to fix your poor indenting.

lol sorry about the poor formatting of the code. I managed to figure out the problem any way so re posting my code wouldnt be of any point. it was just a few brackets here and there. the the last few lines, regarding the digit buffer were supposed to be outside the while loop that converts the ascii values to integer.
Any who, thanks for your interest in my query! Appreciate your enthusiasm to help out!
Regards

it was just a few brackets here and there

That's why consistent indenting, as done by Tools + Auto Format is so important.