16x2 LCD question

Hello I'm new to this forum but I have been programming for sometime. I recently wrote a piece of code to control an LCD display. It take input from a serial terminal and then displays the ASCII for that number. When I send a numbers 1/3 of the time the screen displays an ASCII character that is one higher than what I sent. So if I send a number 32 (space) I get a 33(!) any idea?

hi there. wanna show your code?

without any information i have two guesses: a software off by one error / race condition or harderware error - also try putting a capacitor between GND and PWR on your LCD display. randomly happening errors are usually race conditions or hardware.

Maybe you did

value += (random(0, 3) ? 0 : 1);

Who knows without the code ;)

Oops sorry about that here it is
I’m still testing it and that’s why it may look messy to some people the variables have names that don’t have any meaning to them.

LCDsend(number(0-255),intruction(0) or data(1))

//Variables
int binary[8];
int h;int j=0;int dTime;
//Setup instructions
void setup() {
for(int x=2; x <=13;x++)
{
  pinMode(x,OUTPUT);
}
Serial.begin(9600);
LCDsend(15,0);
LCDsend(1,0);
}
//Main program
void loop() {
  //serial decoder
     if(Serial.available()>0)
    {
      
    int b=-1;int c=-1;int d=-1;int a=-1;
    Serial.println("Waiting...");
    while(b<0)
    {b= Serial.read()-48;}
    while(c<0)
    {c= Serial.read()-48;}
    while(d<0)
    {d= Serial.read()-48;}
    while(a<0)
    {a= Serial.read()-48;}
    dTime = (d*1)+(c*10)+(b*100);
    Serial.println(dTime);
    LCDsend(dTime,a);
    }
}
void LCDsend(int number,int data)
{
  //Decimal to binary converter
 int x =8;
 int temp; 
 int tempt;
 binary[0]=data;
while(x>0)
{
temp = round(number/2);
tempt = number-(temp*2);
if(tempt == 0)
{binary[x]=0;}
else{binary[x]=1;}
number = round((number/2)-0.499999);
x=x-1;
}
//Screen command sender
 x=11;
 int z=0;  
while(x > 2)
{
 digitalWrite(x,binary[z]);
 x=x-1;
 z=z+1;
}
digitalWrite(12,HIGH);
delay(4);
digitalWrite(12,LOW);
}

Please edit your post to have code-tags. See How to use the forum. This with stuff like

binary[x]=0;

in there it's unreadable.

Done

Press ctrl+T in the IDE, how much better does that look?

int binary[8];
//...
int x = 8;
//...
binary[x] = 0;

Oeps.... That's never good.

And the rest, mm, program can use some rewriting....

:o I can read my own program now! Sorry I'm not used to the C syntax very well.