Sliders and Wheels

The mTouch Framework has a special decoding module for sliders and wheels. It can support up to 10 sliders and up to 8 sensors per slider. The sensors used for the slider/wheel are configured as normal touch sensors. They will be scanned as a normal sensor and then, later, decoded as part of the slider.

How It Works

The slider/wheel decoding module is built on top of the normal decoding. It uses the delta readings of the most-pressed sensor and it's most-pressed neighbor to calculate the touched position. An example is shown below:

sliderInterpolation.jpg

Slider Position Interpolation

The interpolated position is calculated as follows:

\[ Interpolated Press Position = (256 \cdot n) \pm \frac{Delta_{n}}{Delta_{n} + Delta_{n \pm 1}} \]

If MTOUCH_SLIDER_SCALING_ENABLED is defined, the scaled interpolated position is calculated:

\[ Scaled Interpolated Press Position = \frac{InterpolatedPressPosition}{n} \]

In the equation, n is the most pressed sensor index.

sliderOutput.jpg

Slider Output Values

Slider/Wheel Configuration

  1. Configure the slider/wheel sensors to be scanned as normal sensors in the mTouch_config.h file. Make sure every parameter is set appropriately, so that it can detect a normal touch. See the main configuration guide for more information on this step.
  2. Open the mTouch_config_slider.h file
    1. Set MTOUCH_NUMBER_OF_SLIDERS to the total number of sliders/wheels you want to implement.
    2. Set MTOUCH_SLIDER_STEP_SIZE. A small step size will smooth your slider result but will limit its speed and response time. The default value (10) will generally give good results.
    3. Enable (recommended) or disable MTOUCH_SLIDER_SCALING_ENABLED based on your needs. If scaling is enabled, the output value will always fall between 0 and 255. If it is disabled, the maximum output value will be dependant on the InterpolatedPressPosition equation shown above.
    4. Configure each individual slider/wheel:
      • For each slider, set MTOUCH_NUMBER_SLIDERx_SENSORS to the number of sensors that will be used to implement this particularly slider/wheel. (Where 'x' is the slider index.)

        Example:

         #define MTOUCH_NUMBER_SLIDER0_SENSORS  4
        

        Slider0 consists of 4 mTouch sensors

      • For each sensor of each slider, set MTOUCH_SLIDERx_SENSORy to the MTOUCH_SENSOR index. (Where 'x' is the slider index and 'y' is the sensor index for that slider.)

        Example:

         #define MTOUCH_SLIDER0_SENSOR1  3
        

        Slider0's second sensor is MTOUCH_SENSOR3

      • Define MTOUCH_SLIDERx_WHEEL_ENABLE if the slider is implemented as a wheel on the PCB. This will have it connect the first and last sensors of the slider in the decoding math, as well as implementing a speed and direction indication for use by the application.

LIMITATION: The framework is not currently able to implement both wheels and sliders in the same application. The framework is not currently able to support more than one wheel. So, the framework is able to support up to 10 sliders with 8 sensors per slider OR one wheel.

Example

Configure two sliders with scaling enabled. The first slider uses 4 sensors and the second slider uses 6.

 // mTouch_config_slider.h

 #define MTOUCH_NUMBER_OF_SLIDERS        2   
 #define MTOUCH_SLIDER_STEP_SIZE         10        
 #define MTOUCH_SLIDER_SCALING_ENABLED       // Slider values will be from 0 to 255

 // mTouch Slider0 Configuration 
 #define MTOUCH_NUMBER_SLIDER0_SENSORS   4   // <-- Number of sensors that make up slider 0
 #define MTOUCH_SLIDER0_SENSOR0          3   
 #define MTOUCH_SLIDER0_SENSOR1          4   
 #define MTOUCH_SLIDER0_SENSOR2          5  
 #define MTOUCH_SLIDER0_SENSOR3          6   
 //#define MTOUCH_SLIDER0_WHEEL_ENABLE       // 'Wheel' disabled
    
 // mTouch Slider1 Configuration 
 #define MTOUCH_NUMBER_SLIDER1_SENSORS   6   // <-- Number of sensors that make up slider 1
 #define MTOUCH_SLIDER1_SENSOR0          7   
 #define MTOUCH_SLIDER1_SENSOR1          8       
 #define MTOUCH_SLIDER1_SENSOR2          9   
 #define MTOUCH_SLIDER1_SENSOR3          10       
 #define MTOUCH_SLIDER1_SENSOR4          11  
 #define MTOUCH_SLIDER1_SENSOR5          12       
 //#define MTOUCH_SLIDER0_WHEEL_ENABLE       // 'Wheel' disabled

Slider/Wheel Output

The framework provides one output for sliders (position) and three outputs for wheels (position, speed, direction).

Slider/Wheel API

The API for handling the slider and wheel outputs are:

Example:

 // Light a line of LEDs based on the slider output value
 // 8 LEDs, 9 total "slider output values" for this application. 0 (all off) to 8 (all on).
 if (mTouch_GetSlider(0) >= 28)  { LED0 = LED_ON; } else { LED0 = LED_OFF; }
 if (mTouch_GetSlider(0) >= 57)  { LED1 = LED_ON; } else { LED1 = LED_OFF; }
 if (mTouch_GetSlider(0) >= 85)  { LED2 = LED_ON; } else { LED2 = LED_OFF; }
 if (mTouch_GetSlider(0) >= 114) { LED3 = LED_ON; } else { LED3 = LED_OFF; }
 if (mTouch_GetSlider(0) >= 142) { LED4 = LED_ON; } else { LED4 = LED_OFF; }
 if (mTouch_GetSlider(0) >= 170) { LED5 = LED_ON; } else { LED5 = LED_OFF; }
 if (mTouch_GetSlider(0) >= 199) { LED6 = LED_ON; } else { LED6 = LED_OFF; }
 if (mTouch_GetSlider(0) >= 227) { LED7 = LED_ON; } else { LED7 = LED_OFF; }
 // Same as above, but with slider scaling disabled.
 // 8 LEDs, 9 total "slider output values" for this application. 0 (all off) to 8 (all on).
 #define MTOUCH_SLIDER0_MAX_VALUE     ((MTOUCH_NUMBER_SLIDER0_SENSORS - 1) * 256)
 if (mTouch_GetSlider(0) >= (uint16_t)( 1/9 * MTOUCH_SLIDER0_MAX_VALUE)) { LED0 = LED_ON; } else { LED0 = LED_OFF; }
 if (mTouch_GetSlider(0) >= (uint16_t)( 2/9 * MTOUCH_SLIDER0_MAX_VALUE)) { LED1 = LED_ON; } else { LED1 = LED_OFF; }
 if (mTouch_GetSlider(0) >= (uint16_t)( 3/9 * MTOUCH_SLIDER0_MAX_VALUE)) { LED2 = LED_ON; } else { LED2 = LED_OFF; }
 if (mTouch_GetSlider(0) >= (uint16_t)( 4/9 * MTOUCH_SLIDER0_MAX_VALUE)) { LED3 = LED_ON; } else { LED3 = LED_OFF; }
 if (mTouch_GetSlider(0) >= (uint16_t)( 5/9 * MTOUCH_SLIDER0_MAX_VALUE)) { LED4 = LED_ON; } else { LED4 = LED_OFF; }
 if (mTouch_GetSlider(0) >= (uint16_t)( 6/9 * MTOUCH_SLIDER0_MAX_VALUE)) { LED5 = LED_ON; } else { LED5 = LED_OFF; }
 if (mTouch_GetSlider(0) >= (uint16_t)( 7/9 * MTOUCH_SLIDER0_MAX_VALUE)) { LED6 = LED_ON; } else { LED6 = LED_OFF; }
 if (mTouch_GetSlider(0) >= (uint16_t)( 8/9 * MTOUCH_SLIDER0_MAX_VALUE)) { LED7 = LED_ON; } else { LED7 = LED_OFF; }

Frequently Asked Questions