Quote:
Originally Posted by AnonymousPencil
Theres no while loop,
|
In an arduino sketch, the code in the void loop() section gets called repeatedly forever.
Quote:
Code:
void loop () {
rightVictor.writeMicroseconds(1000);
delay (15);
}
|
You never told it to.
What your code is doing is repeatedly updating the output PWM signal going out to the motor controller to the same value (1000). It never changes the "speed" you've commanded the motor to travel at. If you wanted the motor to drive for a period of time, then change speed/stop, you need to have that change of event occur within the loop() function.
Something else, you're setting the speed of the motor in the setup function using the
AnalogWrite function. AnalogWrite would be used when you're actually trying to approximate an analog voltage. The output frequency is lower than what you need for some motor controllers. Side note: on paper it looks like it should work with the Victor SP.
I'd suggest revising your code to something more like the following. The reason is the values you use to command the motor speed are different depending on which library you use, and the following code examples won't work correctly unless you are using the servo library.
Code:
Servo rightVictor;// create servo object to control a servo
int rightVictorPin = 10; // twelve servo objects can be created on most boards
void setup() {
rightVictor.attach(rightVictorPin); // attaches the servo on pin 10 to the servo object
}
void loop() {
rightVictor.write(23); // turn the motor at 75% speed in one direction
delay(5000);
rightVictor.write(90); // stop the motor
delay(5000);
}
The above code will loop through the following actions repeatedly:
- run the motor at ~75% speed in one direction
- wait for 5 seconds
- stop the motor from tuning
- wait for 5 seconds
The above code uses the
Servo write() function. It accepts values from 0 to 180. where 0 is full speed in one direction and 180 is full speed in the other direction. Speeds output by the motor controller will be scaled for values between 0 and 180. So a value close to 90 will be off. For this to work perfectly, you may need to calibrate the motor controller for outputs of the above range (0, 180, 90).
Hopefully that helps get you moving in the right direction.