Ok, am building a custom control panel/display for a game called 'Kerbal Space Program'. Someone has made a plugin that pushes data from the game over a serial port which can then be interpreted by an Arduino (anything really...)
I have a Mega2560 that i am using.
I have the LCD panel connected and working (mostly...)
see photo
Currently i have 3 values being displayed. All are floating point numbers, converted to strings so i can manipulate it (check length, add 'units' to the end, etc).
However, when i add more functions the refresh seems to almost die and only update once every minute or so.
The odd thing is it doesn't seem to relate to the actual content. If i turn off other values the new ones work.
I'm not sure if i'm 'overloading' the Arduino and i need to check the way i am doing it.
This is my code, it is not the complete code, only what i am adding to the one that maker of the plugin is posting.
I've tried to make it easy to follow and added in comments, hopefully you can work it out.
Please let me know if you have any questions or suggestions on why this is not working and how to fix it.
Thanks!
void LCD() {
//Runs Functions that display various readouts on the LCD Screen
VOrbit();
APPE(VData.AP,"AP=");
APPE(VData.PE,"PE=");
Escape();
//OrbitInc();
}
//Function to convert a Floating Point value to a String which is left justified, no 'extra' spaces
String FloatToString(float Float, int Dec){
char dtostrfbuffer[8];
dtostrf(Float,-1, Dec, dtostrfbuffer);
return dtostrfbuffer;
}
//Function to clean up any 'trash' characters on the LCD screen by adding spaces to the end of the final String by checking the length of the String against the 'max length' passed to it.
String CheckLength (String DataString, int Length) {
while (DataString.length() < Length) {
DataString = DataString + " ";
}
return DataString;
}
//Function to work out the Orbit Velocity and display it
void VOrbit(){
lcd.setCursor(0, 3);
int Dec = 2;
String AP = (FloatToString(VData.VOrbit, Dec) + "ms");
String StrLen = CheckLength(AP,11);
lcd.print("V=" + StrLen);
}
//Function to display the AP and the PE
void APPE(float APPE, String Name){
String SpeedUnit = "m";
int Dec=2;
//If reading is over 1000m, convert to km
if (APPE > 1000.00) {
APPE = APPE / 1000.00;
SpeedUnit = "km";
}
//If reading is over 1000km, convert to Mm
if (APPE > 1000.00) {
APPE = APPE / 1000.00;
SpeedUnit = "Mm";
int Dec=3;
}
//Check that the reading is the 'AP' and then display it
if (Name == "AP=") {
lcd.setCursor(0, 0);
if (VData.AP <= 0.00){
lcd.print(Name + "0.00m");
} else {
String AP = (FloatToString(APPE, Dec) + SpeedUnit);
String StrLen = CheckLength(AP,8);
lcd.print(Name + StrLen);
}
}
//Check that the reading is the 'PE' and then display it
if (Name == "PE=") {
lcd.setCursor(0, 1);
if (VData.PE <= 0.00){
lcd.print(Name + "0.00m");
} else {
String PE = (FloatToString(APPE, Dec) + SpeedUnit);
String StrLen = CheckLength(PE,8);
lcd.print(Name + StrLen);
}
}
}
//Function to determine the Orbit reading and if you are on an 'escape' tradjectory.
void Escape() {
lcd.setCursor(12, 0);
int Dec = 2;
String escape = (FloatToString(VData.e, Dec));
if (VData.e > 1.00) {
lcd.print("Escape");
} else {
lcd.print(escape);
}
}
//Function to display the Orbit angle
void OrbitInc() {
lcd.setCursor(12, 1);
int Dec = 2;
//(char)223 displays a 'degree' symbol.
String Inc = (FloatToString(VData.inc, Dec) + ((char)223));
lcd.print(Inc);
}