I have an ultra simple program that doesn't seem to work.
// Show problem(?) with floating point
// 01-06-2015
void setup() {
Serial.begin(115200);
Serial.println("setup() ");
}
void loop() {
float x;
x = x + 1.01;
Serial.println(x);
delay(1000);
}
The println statement shows the same value "1.01" without changing. I've tried a variety of changes:
I tried x += 1.01; with the same result
I tried float x = 0.0; with the same result
As I ran out of idea's I tried setting the delay() to different values - same result
I have a Basic I/O board connected and I sent the result to the LCD - same result
The only way I can make it work is if I move the float statement to make "x" a global variable. It then works. Why does it have to be a global variable? I assume I must be doing something wrong, but I don't know what.
Can anyone help?
Thanks,
EigenFunctions
BTW- I'm running with Win7 using the ChipKit Max32 USB cable directly;
Question
EigenFunctions
I have an ultra simple program that doesn't seem to work.
The println statement shows the same value "1.01" without changing. I've tried a variety of changes:
The only way I can make it work is if I move the float statement to make "x" a global variable. It then works. Why does it have to be a global variable? I assume I must be doing something wrong, but I don't know what.
Can anyone help?
Thanks,
EigenFunctions
BTW- I'm running with Win7 using the ChipKit Max32 USB cable directly;
Mpide 0023-windows-20140821
Link to comment
Share on other sites
7 answers to this question
Recommended Posts
Archived
This topic is now archived and is closed to further replies.