C++ Math with diffrent types, when do i cast? -


while writing short program arduino pro mini (atmega328, 8mhz) thought math part , want optimize it, don't know wich way best.

since i'm working on 8bit without dedicated float math, , space(sram) rare, want have in integer-math possible (is correct?)

here part of code, have not included casts now, keep clean.

//in future can change (that's why no "const") uint8_t deadband = 2;  uint8_t amp_fwd = 20; uint8_t amp_break = 5;  int8_t throttle; //this read potentiometer  if (throttle > deadband){   outputfwd(throttle * amp_fwd / 127); } else if (throttle < -deadband) {   outputbreak((throttle + 127) * amp_break / (127 - amp_break)); } else {   outputfwd(0);   outputbreak(0); }  void outputfwd(float ampere){} // positive values void outputbreak(float ampere){} // positive values 

some explanation:

it's control motor. reads value (throttle) potentiometer. on mid throttle (0 127) drives fwd output , below (-127 0) drives breaks. have included deadband can see, won't swing between these two.

looking @ outputbreak had idea. sufficient make "127" float/decimal (write 127.0)? or have cast before every variable (that's did before...). idea change definitions of variables float.

thank time , casts. regards


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -