I found out about the Logger today and am using the pod/SimpleLed example program to experiment with it. When I try to print a float
with the %f
format string (I also tried %e
and %g
), it seems to crash the Daisy.
Here’s my program:
#include "daisy_pod.h"
using namespace daisy;
DaisyPod hw;
Parameter p_knob1, p_knob2;
int main(void)
{
hw.Init();
// Wait for the PC to connect before continuing.
hw.seed.StartLog(true);
float r = 0, g = 0, b = 0;
int previousR = -1;
p_knob1.Init(hw.knob1, 0, 1, Parameter::LINEAR);
p_knob2.Init(hw.knob2, 0, 1, Parameter::LINEAR);
hw.StartAdc();
while(1)
{
r = p_knob1.Process();
g = p_knob2.Process();
if ((int)(r * 10) != previousR)
{
previousR = (int)(r * 10);
hw.seed.PrintLine("previousR is %d", previousR);
// The following line is the one that causes problems.
hw.seed.PrintLine("r is %f", r);
}
hw.led1.Set(r, g, b);
hw.UpdateLeds();
}
}
When I run this program I see this in the terminal window and the LED is not lit:
Daisy is online
===============
previousR is 0
If I comment out the problem line I get this and the program works as expected:
Daisy is online
===============
previousR is 0
previousR is 4
previousR is 5
previousR is 6
previousR is 5
previousR is 6
previousR is 5
If I change the problem line to hw.seed.PrintLine("r is %d", r);
I get this and the LED works (but the value is obviously wrong because the format string doesn’t match the data type):
Daisy is online
===============
previousR is 0
r is 603995752
previousR is 6
r is 603995752
previousR is 5
r is 603995752
previousR is 6
r is 603995752
Why does this not work with %f
? Does PrintLine
not use the same formatting strings as printf
in C++?