Replace a rotary switch with a potentiometer #Engineering #Engineers
From the example above, going from state #2 to state #1 requires that the potentiometer value go below the lower transition point of 74 by 4; thus the lower threshold value is 70. Conversely, going from state #1 to state #2 requires that the potentiometer value go above the upper transition point of 73 by 4; thus the upper threshold value is 77. The table used for the program code only requires the high and low threshold values, in this case only 14 bytes. The code example below was run on a Silicon Labs C8051F310 (8051 architecture) – however it is easily adaptable to your microcontroller of choice. A fast table look-up combined with 37 instructions results in a minimal execution time, the dominant part being the ADC conversion time of ~5µs. The subroutine POT2SW is called once the ADC value is read into the accumulator.