I have two functions that are very similar and both have the same problems.
I start by getting a number from the serial buffer then, I send that number to a function. I want the function to produce a result such as the text "TRUE" or "False" for one function, and "In" or "Out" for the other function. I will then be saving the result to variable to later be saved to a SD card.
My SD card results will need to look like this when done.
Log Time RPM TPS IAP HO2 HO2 Wideband IGN STP GEAR CLUTCH NT
00:00.0 1130 56 44 47 65535 38 26 0 Out TRUE
00:00.2 1180 56 50 47 65535 38 26 0 Out TRUE
Below are both the functions that I am having trouble with. I have trouble initializing them properly and my array size does not work with 2 different text results that have different amount of letters. I hope I have provided enough information, I am struggling to use the proper terms for asking the question. I added comments in the code to help follow my line of thinking.
Could some one help me please?
/////////////////////////////////Parts for function #1/////////////////////////
//Get the variable Clutch from the buffer (buf)
Clutch = buf[CLUTCH] & 0x10; //clutch must = IN OR OUT, if clutch = 0 it is "out", if clutch = 1 it is "in"
//Send vairable Clutch to function CLUTCHCHECK() and make a "TRUE" or "False" result
char clutchStr = CLUTCHCHECK(Clutch);
//Receive Clutch becomes ClutchState, then test for 0 or 1
char CLUTCHCHECK(int ClutchState)
if (ClutchState == 0)
C = "Out";
else // ClutchState should be 1 if it is not 0
C = "In";
return C; //return "In" or "Out"
////////////////////////////////////Part for function #2///////////////////////////////////////
//Get the variable Nt from the buffer (buf)
Nt = buf[NEUTRAL] & 0x02; //neutral MUST = TRUE OR FALSE (2 = false) (0 = true)
//Send vairable Nt to function NEUTRALCHECK() and make a "TRUE" or "False" result
char neutralStr = NEUTRALCHECK(Nt);
//Receive Nt becomes NeutralState, then test for 0 or 2
char NEUTRALCHECK(int NeutralState)
if (NeutralState == 0)
N = "TRUE";
else // if not 0, NeutralState should be 2
N = "FALSE";
return N; // return "TRUE" or "FALSE"