Update:
Here is my first try based on the code I found and it did not work. The first time I uploaded it, it move to the "current positional value". But did not do the void loop part. Just holds the positions.
Thanks.
//Includes
#include <Servo.h>
//Defines
#define LINEAR_1_100PIN 11 //Linear Actuator Digital Pin
#define LINEAR_2_100PIN 6 //Linear Actuator Digital Pin
String msg;
//max/min pulse values in microseconds for the linear actuators
#define LINEAR_1_100_MIN 1050 //
#define LINEAR_1_100_MAX 2000 //
#define LINEAR_2_100_MIN 1050 //
#define LINEAR_2_100_MAX 2000 //
Servo LINEAR_1_100, LINEAR_2_100; // create servo objects to control the linear actuators
//int knobValue, sliderValue; //variables to hold the last reading from the analog pins
int linear100Value_1 = 1051; //current positional value being sent to the linear actuator.
int linear100Value_2 = 1051; //current positional value being sent to the linear actuator.
int speed = 10;
void setup()
{
//initialize servos
LINEAR_1_100.attach(LINEAR_1_100PIN, LINEAR_1_100_MIN, LINEAR_1_100_MAX); // attaches/activates the linear actuator as a servo object
LINEAR_2_100.attach(LINEAR_2_100PIN, LINEAR_2_100_MIN, LINEAR_2_100_MAX); // attaches/activates the linear actuator as a servo object
//Analog pins do not need to be initialized
//use the writeMicroseconds to set the linear actuators to their default positions
LINEAR_1_100.writeMicroseconds(linear100Value_1);
LINEAR_2_100.writeMicroseconds(linear100Value_2);
}
void loop()
{
LINEAR_1_100.write(90);
delay(1000);
LINEAR_1_100.write(0);
delay(1000);
LINEAR_2_100.write(90);
delay(1000);
LINEAR_2_100.write(0);
delay(1000);
}
Old Question:
I am trying to make the code described in this tutorial:
work with PWM from an Arduino, without the additional board.
So far the Arduino Examples>Servo>Sweep works as I would like to achieve it (delay changed to 30 ms) but very slowly and it does not seem to just go 180 steps out wait 30 ms and 180 steps in again. It sometimes moves twice in one direction. If I change the steps from 1 to 5 the servo does not move anymore (I expected it to go faster).
With the code above I understand I can control the servo with a Knob or Slider, but I would like to understand how I can control this Linear Actuator Servo with PWM from an Arduino PMW Pin (e.g. 11) and change the speed. Finally I would like to make the Servo consistently go x amount of steps out, wait for x ms and the same amount back in again.
Most importantly I would like to make sure it always ends at position 0, and that it does not accumulate errors.
Thank you for any help.