Hi
New to Arduino, C, and last programmed in anger over 20 years ago, so please bear with me.
I am trying to develop an engine monitoring system, (engine hours, oil pressue, water temperature, fuel level, battery voltage, etc. with alarms) but finding the programming environment a little challenging.
I have been having a quirky problem and thought it was the 'for' loop going out of control - as one did before, but it is evidently the assignment of the zero to the last character in charbuff. If you comment out that statement, the loop works ok: As it is, it compiles, but jumps out of loop() back into setup()!
#include <SoftwareSerial.h>;
#define TRACE1
#ifdef TRACE1
#define trace1(s) Serial.print(s)
#define traceln1(s) Serial.println(s)
#else
#define trace1(s)
#define traceln1(s)
#endif
char charbuff[6];
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
traceln1("Starting");
}
void loop() {
// put your main code here, to run repeatedly:
traceln1("here ok");
for (int k = 1; k < 6; k ++ ){ //I am simply trying to initialise a buffer to spaces, prior to putting an integer converted to ascii - ultimately to output to LCD
charbuff[k] = 32;
trace1 (k); traceln1(" In k-loop");
delay(1000);
}
charbuff[6] = 0; //comment this out and it executes ok
trace1(charbuff); traceln1(" On Exit k");
// delay(2000);
}
I am probably misunderstanding the nature of char as opposed to char * as I have not got my head around what you can and cannot do.
In fact I am ludicrously spending hours trying to format a message including hours, minutes to log events, so need to get an integer into ascii an ascii string, and concatenate elements for output to LCD and to the monitor, possiblly a web page later. It can't be this hard, surely?
Anyoone who has time to mentor me with my silly questions without being too rude in the process would be most welcome.