I am fairly new to embedded c++ outside of Arduino, but so far I have been able to fix all the problems I have run into, except this one. I am using Atmel Studio on an Atmega 1284P, coding in C++. I am using the following variables to compare to TTL Serial input (the serial input is between 0 and 255 transferred in a single unsigned char byte):
const unsigned char STEER_DEADZONE_MIN = 120;
const unsigned char STEER_DEADZONE_MAX = 120;
const unsigned char THROTTLE_DEADZONE_MIN = 136;
const unsigned char THROTTLE_DEADZONE_MAX = 136;
When I try to use STEER_DEADZONE_MIN or any of the listed unsigned chars they come out as 12. I have confirmed that my program sees it as 12 using both the Atmel Studio simulator watch tool and by printing it out to the LCD on the embedded device. I have actually come up with a fix for the unsigned char which is to remove const, but I have const there for a reason, since I don't want the value changed. Declaring it as:
unsigned char TEST = 120;
unsigned char TEST1 = 136;
this causes the value to correctly be 120 or 136, but then the value can be accidentally changed. It also seems that if I do the assignment inside my main loop as:
const unsigned char TEST = 120;
This also fixes the value, but introduces other problems since then none of my functions can access it.
I am also having a seemingly related issue When it comes to a const unsigned int. When I declare it outside the main loop:
const unsigned int SERVO_ESC_SPEED = 200;
const unsigned int SERVO_STEER_SPEED = 200;
const unsigned int SERVO_DISTANCE_SENSOR_SPEED = 200;
The value comes out as 37900, but, I have tried declaring it inside my main loop as:
const unsigned int TEST = 200;
That corrects the value, but as above, does not help since my functions no longer have access to it. In this case, removing const outside the main loop doesn't fix the value. I am really at a loss at this point. I only other thing that I can think of to try at this point is to create a settings class with all these const variables and see if that corrects the values. I will be trying that next and updating with results.