c++ - Can't assign value of 120 to static const unsigned char or value of 200 to const static unsigned int -


i new embedded c++ outside of arduino, far have been able fix problems have run into, except one. using atmel studio on atmega 1284p, coding in c++. using following variables compare ttl serial input (the serial input between 0 , 255 transferred in 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 try use steer_deadzone_min or of listed unsigned chars come out 12. have confirmed program sees 12 using both atmel studio simulator watch tool , printing out lcd on embedded device. have come fix unsigned char remove const, have const there reason, since don't want value changed. declaring as:

unsigned char test = 120; unsigned char test1 = 136; 

this causes value correctly 120 or 136, value can accidentally changed. seems if assignment inside main loop as:

const unsigned char test = 120; 

this fixes value, introduces other problems since none of functions can access it.

i having seemingly related issue when comes const unsigned int. when declare outside 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 37900, but, have tried declaring inside main loop as:

const unsigned int test = 200; 

that corrects value, above, not since functions no longer have access it. in case, removing const outside main loop doesn't fix value. @ loss @ point. other thing can think of try @ point create settings class these const variables , see if corrects values. trying next , updating results.

what making them static too?

static const unsigned char steer_deadzone_min = 120; static const unsigned char steer_deadzone_max = 120; static const unsigned char throttle_deadzone_min = 136; static const unsigned char throttle_deadzone_max = 136; 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -