Go Down

Topic: coarse / fine potmeter function (Read 1 time) previous topic - next topic

robtillaart

needed a 16 bit fine control in an experiment and I realized it with two potmeters, one for coarse and one for fine control

After some tweaking I got this more generic function

Code: [Select]

uint16_t analogR(uint8_t coarsePin, uint8_t finePin, uint8_t bits)   // bits = bits per potmeter 1..8, so the result will be twice that nr of bits.
{
  if (bits > 8) return 0; 
  uint8_t shift = 10-bits;

  // analogRead(coarsePin); // opt. to remove noise by double read
  uint16_t value = (analogRead(coarsePin) >> shift) << bits;

  // analogRead(finePin);
  return value & (analogRead(finePin) >> shift);
}


I restricted the number of bits per pot to 8 to minimize noise fluctuations.

thoughts for improvement:
* three pots? four?
* why restrict both pots to same # bits?   
* how to do odd # bits? e.g. 15 bits so I could use the sign bit for errors.

just to share
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy