I bought new High letgo slide pot and it performs very eraticly.
There is supposed to be a min and max value, but when I write them down, they change in a matter of seconds.
for example limits I've received during 1 minute
470 490
428 384
444 400
any suggestions on what to do ?
Is there a way to get larger range?
My current program turns on 2 leds. if potentiometer is on left then left led turns on and vice versa, and if in middle no led.
// left right
//500 455 426 404
const int left = 430; //pot left value
const int right = 410; //pot right value
const int ledL = 10;
const int ledC = 5;
const int ledR = 11;
const int dirPin = 13;
int mult = 10;
float conNum = 0.00441;
int sensorPin = 13; //pin number to use the ADC
int sensorValue = 0; //initialization of sensor variable, equivalent to EMA Y
float EMA_a = 0.6; //initialization of EMA alpha
int EMA_S = 0; //initialization of EMA S
void setup() {
Serial.begin(9600);
pinMode(dirPin, INPUT );
}
void loop() {
/*int dir = analogRead(dirPin);
Serial.print("Slide Pot value: ");
Serial.println(dir);
*/
//delay(2000);
// left right
//467 445 426 404
//113 100
/*
* int dir = analogRead(dirPin);
dir = dir >> 2;
dir = dir*mult;
*/
float dir = readPotEma();
if(dir > left) {
Serial.print("In left ");
Serial.println(dir);
digitalWrite(ledR, LOW);
analogWrite(ledL,dir);
}/* else if(dir < left && dir > right) {
analogWrite(ledC, dir);
} */else if(dir < right) {
Serial.print("In right ");
Serial.println(dir);
digitalWrite(ledL, LOW);
analogWrite(ledR, dir);
}else {
Serial.print("In center ");
Serial.println(dir);
digitalWrite(ledL, LOW);
digitalWrite(ledR, LOW);
}
}
float readPotentiometer(void){
float pos;
pos = conNum*(analogRead(dirPin) - 44); // 44 ADC is equal to 0"
return pos;
}
int readPotEma() {
sensorValue = analogRead(sensorPin); //read the sensor value using ADC
EMA_S = (EMA_a*sensorValue) + ((1-EMA_a)*EMA_S); //run the EMA
return EMA_S;
}