Hi,
my sketch does not print within setup().
This code is part of a longer code for some tests. The function makeTimeStr() shall be used to print elapsed times, e.g.
...
tm=millis();
...
Serial.print(makeTimeStr(millis()-tm)):
...
#include <LCD5110_Graph.h>
#define DISP_BR 84
#define DISP_HO 48
#define BATT_BR 15
#define BATT_HO 30
#define A_BATT 6
LCD5110 myGLCD(9,10,11,12,13);
extern unsigned char SmallFont[];
extern unsigned char TinyFont[];
int pwm=100, dpwm=5, pw_1=0, pw_2=0, pw_off=185;
int V_batt, V_d, V_g, V_d0, V_d2, V_bold;
int V_charge, V_off1, V_off2, V_disch1, V_disch2, vw;
const word aR2V=45300/1023; // V++ = 4,75 V
//const word scale=10000;
unsigned long tm, t0, t_load=5000, t_off=1000, t_discharge=800;
int dt;
byte state=0;
int ncloops=0, ncl; // zaehlt die Anzahl Regelschleifenlaeufe
word V_soll=100;
char TStr[12];
bool SM=true;
// makeTimeStr erzeugt aus dt einen String der Form hh:mm:ss
char* makeTimeStr(unsigned long dt) {
char hmsTime[12], hstr[6];
word tt;
dt /= 1000; // make seconds
tt = dt/3600;
if (SM) {
Serial.print(tt); Serial.print(" ");
}
sprintf(hmsTime,"%02d:",tt);
dt = dt- tt*3600;
tt = dt/60;
if (SM) {
Serial.print(tt); Serial.print(" ");
}
sprintf(hstr,"%02d:", tt);
strcat(hmsTime, hstr);
tt = dt- tt*60;
if (SM) {
Serial.println(tt);
}
sprintf(hstr,"%02d ", tt);
strcat(hmsTime, hstr);
if (SM) Serial.println(hmsTime);
}
void setup() {
// put your setup code here, to run once:
myGLCD.InitLCD();
myGLCD.setFont(SmallFont); // SmallFont=6x8
Serial.begin(38400);
pinMode(3,OUTPUT);
analogWrite(3,pwm);
ncl=ncloops;
delay(800);
V_batt=analogRead(A6);
V_bold=V_batt;
V_d=V_batt;
Serial.println("in setup ");
if (SM) Serial.println(makeTimeStr(7000000));
tm=millis();
t0=tm;
state=0;
pw_off=185;
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("in loop");
delay(1000);
}
When running this code the output is:
in setup
1 56 40 <--- print within makeTimeStr()
01:56:40 <--- print within makeTimeStr()
<--- missing print within setup()
in loop
in loop
...
I am in doubt if it is generally allowed to return a pointer to a string within makeTimeStr() because
the pointer is pointing to somewhere on the stack.
On the other hand the returned pointer is immediately used as a parameter of print.
What is the reason why there is no print output?