I am using my arduino to control a linear actuator (motor). Right now, it entends at speed 255 (full speed, based on a range from 0 - 255), it pauses, then it retracts at speed 255. The code to do the retraction is simply setting the speed to 255 on the "Raise" PWM pin and waiting a second while it comes up, before any more code is executed. This is what I have:
...where "time" goes from 0 seconds (the start of that delay in my code above) to 1000 milliseconds. This would decrease the speed non-linearly, slowing it down more as we get closer to the end of the second. I'm not sure how to "start a timer" if you will, to allow this function to work properly. Anyone know how I can implement this idea?
Quit using the delay(...) function and learn to use the millis() function. If you need it, there is a great tutorial near the top of this forum.
The millis() function will tell you the time (as an unsigned long) that you started, and the difference between millis() and the time that you started will tell you how much time has passed. If the difference is greater than 1000 then more than one second (1000 milliseconds) has passed.
When it comes to using millis(), all variables involved with time calculations should be declared unsigned long and the calculations should be subtraction, NEVER addition.