widdly
12
I’d try moving some of those global variables to static variables inside functions if possible. For example current_value and previous_value are only used in the loop function so you can move them into that function and declare them static.
I’d get rid of the global channel const. It is confusing since it is also used as an argument name to functions.
I’d be a bit concerned about the calibrateSensor function getting stuck in the while(calib_bool) loop. Turn the led on just before that while statement and turn it off at the very end of that function. I’d bet it gets stuck on at some stage. It is generally a bad idea to rely on external sensor data to break out of an infinite loop.
This bit of code is silly…
while (calibrate_flag == 1) {
// actual calibration function
calibrateSensor();
// terminate while loop
calibrate_flag = 0;
} … change the while to an if
1 Like