Hi! I have a variable that was defined at the header (value of a reference resistor). This variable was used in different test functions I made. Now on Calibration mode, over time the value changes and it was read by the calibration. How do I redefine that variable to be use on future function tests. Thank you
You mean defined with #define?
You can simply change the value in IDE. But then you would need to recompile for each calibration.
If you want to change it run time you must put it in a variable. The variable can be changed then.
#define R1 330
int resistor1 = R1;
loop() {
if (something) {
resistor1 = 320;
}
}
Maybe it is a good idea to save calibration parameters in EEPROM. Then they will still be there if you switch off your MCU.
Thanks a lot. That's what I'm thinking. I read on stackflow about shadowing? Can it be an option?
If you declare another int resistor1 within a more narrow scope (within{}) that will be a completely different variable. It shadows the value from outer scope. From a software engineering point this is bad practice as it will confuse yourself and others.
So it might solve your problem, but it might not be the best way.
Okay. Thanks a lot. I'm going with the eeprom