Jump to content

dirkr

Members
  • Posts

    2
  • Joined

  • Last visited

Everything posted by dirkr

  1. Yes, sure. Maybe precision is the better term. The Arduino reads 1024 different analog values as 0,1,2,3,...1024. With the code above you would get 0,4,8,...1020 instead, which means that you effectively get 255 different values across the total physical movement. For me this doesn't matter as my pots anyway do not have this precision. When reporting to DCS the value is multiplied with 64, so the final values are 0, 256, 512, 768 ... 65280. Dirk
  2. I solved this problem by implementing sort of a hysteresis between input and reported value, similar to the debouncing of switches. I added two more private variables in Potentiometer : PollingInput... unsigned int lastState_; unsigned int lastRepState_; ...and then used a two-stages approach. First detect, if the difference between actual and last state is greater then 3, then apply some sort of rounding for the reported value and compare if it differs from the last reported value. void Potentiometer::pollInput() { unsigned int state = (analogRead(pin_)); if (abs(state - lastState_)>3) { int rep=(state/4)*256; if (rep != lastRepState_) { char buf[6]; utoa(rep, buf, 10); sendDcsBiosMessage(msg_, buf); lastRepState_=rep; } lastState_ = state; } } By doing that, the accuracy is reduced to a 4th, but I do not get these constant output flows. Hope that helps, Dirk
×
×
  • Create New...