So my problem is that everything works good until a minute and then x-sim pops up with "Error writing on serial port"
I think it happens because sometimes my cpu usage is at 100.5%
But I really don't know, please help, me people! Thanks in advance!
Error:

Setup:
-RPM

-GEAR

-SPEED

USO:

CODE FOR ARDUINO:
- Code: Select all
#include <LiquidCrystal.h>
LiquidCrystal lcd (12, 11, 5, 4, 3, 2);
void setup()
{
Serial.begin(115200);
lcd.begin(20, 4);
lcd.print("LOADING");
lcd.clear();
}
void loop()
{
if (Serial.available())
{
//Get data from serial
char kindofdata = Serial.read();
int reading = Serial.parseInt();
//Send data to the write command
writetolcd(kindofdata, reading);
}
}
void writetolcd(char kind, int data)
{
//Read the kind of data
if (kind == 'R')
{
if (data * 33 >= 6200) digitalWrite(13, HIGH);
else digitalWrite(13, LOW);
lcd.setCursor(1, 1);
lcd.print("RPM : ");
lcd.setCursor(7, 1);
lcd.print(" ");
lcd.setCursor(7, 1);
lcd.print(data * 33); //Convert data to a more accurate reading
return;
}
//Read the kind of data
if (kind == 'G')
{
lcd.setCursor(1, 2);
lcd.print("Gear : ");
lcd.setCursor(8, 2);
if (data == 255) lcd.print("R");
else if (data == 0) lcd.print("1");
else if (data == 36) lcd.print("2");
else if (data == 73) lcd.print("3");
else if (data == 109) lcd.print("4");
else if (data == 146) lcd.print("5");
else if (data == 223) lcd.print("6");
else if (data == 239) lcd.print("7");
else if (data == 255) lcd.print("8");
return;
}
//Read the kind of data
if (kind == 'S')
{
lcd.setCursor(1, 0);
lcd.print("Speed : ");
lcd.setCursor(12, 0);
lcd.print("Km/h");
lcd.setCursor(9, 0);
lcd.print(" ");
lcd.setCursor(9, 0);
lcd.print(data * 2);
return;
}
return;
}
I'm going to change the shift light so, I can determine the rpm at which the led turns on, but as long as I don't get this problem fixed I'm not really gonna be doing much else.
Thanks in advance!
Regards,
--Valentin