I’m working on a project that need to read values from six 10K potentiometer sliders,
that connected to analog pins, An0 - An5 (See images for schematic.)
Everything seem to work well. But one thing that I am not happy with it is that
whenever I slide one of the sliders up and down (I set the scale for all the sliders between 0-255).
All the other sliders seem to increase/decrease the value as well.(see the debug result on the image.)
The values seem to be in the ~10% range of the one that is used.
This is probably a noise among the analog pins (An0 - An5)???
My question is that if there are any way to get ride of these noise?
And how, any suggestion?
Here si the code that I use to measure the values of the sliders:
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware;
namespace FEZ_Panda_Application1
{
public class Program
{
const int avgCount = 6;
// Slider Potentiometers
//Color, Saturation, Bright, Transparent, Width, Fade;
static AnalogIn colorSlider = new AnalogIn((AnalogIn.Pin)FEZ_Pin.AnalogIn.An0);
static AnalogIn saturateSlider = new AnalogIn((AnalogIn.Pin)FEZ_Pin.AnalogIn.An1);
static AnalogIn brightSlider = new AnalogIn((AnalogIn.Pin)FEZ_Pin.AnalogIn.An2);
static AnalogIn transparentSlider = new AnalogIn((AnalogIn.Pin)FEZ_Pin.AnalogIn.An3);
static AnalogIn widthSlider = new AnalogIn((AnalogIn.Pin)FEZ_Pin.AnalogIn.An4);
static AnalogIn fadeSlider = new AnalogIn((AnalogIn.Pin)FEZ_Pin.AnalogIn.An5);
static int colorValue, saturationValue, brightValue, transparentValue, widthValue, fadeValue;
static int[] colorAvg = new int[avgCount];
static int[] saturationAvg = new int[avgCount];
static int[] brightAvg = new int[avgCount];
static int[] transparentAvg = new int[avgCount];
static int[] widthAvg = new int[avgCount];
static int[] fadeAvg = new int[avgCount];
//Button
static bool buttonState;
static InputPort Button = new InputPort((Cpu.Pin)FEZ_Pin.Digital.Di7, true,
Port.ResistorMode.PullUp);
public static void Main()
{
int index = 0;
colorSlider.SetLinearScale(0, 256);
saturateSlider.SetLinearScale(0, 256);
brightSlider.SetLinearScale(0, 256);
transparentSlider.SetLinearScale(0, 256);
widthSlider.SetLinearScale(0, 256);
fadeSlider.SetLinearScale(0, 256);
//reset sliders average
for (int i = 0; i < avgCount; i++)
{
colorAvg[i] = 0;
saturationAvg[i] = 0;
brightAvg[i] = 0;
transparentAvg[i] = 0;
widthAvg[i] = 0;
fadeAvg[i] = 0;
}
while (true)
{
//Read button
buttonState = Button.Read();
//calc average value
colorAvg[index] = colorSlider.Read();
saturationAvg[index] = saturateSlider.Read();
brightAvg[index] = brightSlider.Read();
transparentAvg[index] = transparentSlider.Read();
widthAvg[index] = widthSlider.Read();
fadeAvg[index] = fadeSlider.Read();
// increment index, if index > array size reset to zero
index++;
if (index >= avgCount)
index = 0;
// calc sliders average value
slidersAverage();
Thread.Sleep(10);
//Display the sliders' value
Debug.Print("Sliders: " +
(colorValue).ToString() + "\t" + (saturationValue).ToString() + "\t" +
(brightValue).ToString() + "\t" + (transparentValue).ToString() + "\t" +
(widthValue).ToString() + "\t" + (fadeValue).ToString());
Debug.Print("Button: " + buttonState.ToString());
}
}
public static void slidersAverage()
{
colorValue = 0;
saturationValue = 0;
brightValue = 0;
transparentValue = 0;
widthValue = 0;
fadeValue = 0;
for (int i = 0; i < avgCount; i++)
{
colorValue += colorAvg[i];
saturationValue += saturationAvg[i];
brightValue += brightAvg[i];
transparentValue += transparentAvg[i];
widthValue += widthAvg[i];
fadeValue += fadeAvg[i];
}
colorValue /= avgCount;
saturationValue /= avgCount;
brightValue /= avgCount;
transparentValue /= avgCount;
widthValue /= avgCount;
fadeValue /= avgCount;
}
}
}