Reduce a value over time

Hi,

I have very little knowlegde of writing code. My project code has been constructed by cut and paste and some learning. However, I'm stumped on how to express what you could describe as a "leaking" value.

I have a potentiometer controlling a wiper motor.
When I set the pot to 100 (x), after 5 seconds I want (x) to decrease by 2 every 3 seconds until it reaches 50 and use the product as the new setpoint.

I came across this Reducing a variable every x seconds [Arduino Uno] - Project Guidance - Arduino Forum but when I tried replacing "variable" with my pot I got nothing

Can you guide me to the solution?

Thanks

Please post your sketch and maybe we can help.

//decrease x by 2 every 3 seconds

prev = millis();  //put this in setup

if((millis()-prev) > 3000) {   //put this in loop
     x=x-2;
     prev=millis();
}

//check if x ==50
if (x==50)
 {do something}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.