Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

Close

Variable Pot | Electronics Lab

Variable Pot
Version 1 - Last update: Oct 5, 2015

Read the Pot Value only when it has changed beyond a particular scale

int count = 0; int lastValue = 0; int analog_threshold = 6;

void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); }

// the loop routine runs over and over again forever: void loop() { // read the input on analog pin 0: int sensorValue = analogRead(A0);

// print out the value you read: if(sensorValue <= (lastValue-analogthreshold) || sensorValue >= (lastValue+analogthreshold) ){ int scaledValue = map(sensorValue,0,1023,0,127); Serial.print("Count = "); Serial.print(count++); Serial.print(" ,SensorValue = "); Serial.print(sensorValue); Serial.print(" ,scaledValue = "); Serial.println(scaledValue); lastValue = sensorValue; //Serial.print(" ,lastValue = "); //Serial.println(lastValue);
} delay(1); // delay in between reads for stability
}

Comments disabled