Greetings! Pardon me if this question has been answered before. I did not read anything resembling my question.
I'm trying to sketch a 360 servo for camera slider and have copied code that works with my setup and have tweaked the numbers to fit my purpose. I'm also trying to work a standard servo to click my remote intervalometer, mechanically, using a horn arm, for fear of frying my camera if i click it automatically using arduino uno. When I get more experienced I'll let the arduino do all the work. Maybe you could steer me in the right direction.
I have the 2 sketches working perfectly by themselves but when I write them together in one sketch, i get errors. I may have syntax issues.
Here's what I have.
For 360 continuous servo:
#include <Servo.h>
Servo Ron1; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup()
{
Ron1.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
Ron1.write(91.5); // tell servo to go to position in variable 'pos'
delay(1); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=0; pos-=1) // goes from 180 degrees to 0 degrees
{
Ron1.write(87); // tell servo to go to position in variable 'pos'
delay(65.9); // waits 15ms for the servo to reach the position
}
And for standard micro servo:
#include <Servo.h>
Servo Ron2; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup()
{
Ron2.attach(10); // attaches the servo on pin 10 to the servo object
}
void loop()
{
for(pos = 180; pos <= 0; pos += 1) // goes from 0 degrees to 25 degrees
{ // in steps of 1 degree
Ron2.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15ms for the servo to reach the position
}
for(pos = 50; pos>=0; pos-=1) // goes from 20 degrees to 0 degrees
{
Ron2.write(pos); // tell servo to go to position in variable 'pos'
delay(300); // waits 15ms for the servo to reach the position
}
}
You cannot control the position of a continuous rotation servo - only its speed and direction. Hence there is no point having a FOR loop. Just leave it to work for whatever time is needed to move the distance you want.
If you post your code using the code button </>
so it looks like this
I will be able to select it and copy it to my text editor and give you more advice.
Sorry for the newbie mistakes. Here's the codes where they're supposed to be placed as attachment that I'm trying to tie-in together in one arduino uno sketch.
And this is the error message:
Arduino: 1.6.5 (Windows 7), Board: "Arduino Uno"
sketch_aug27_standard_and_360_servo.ino: In function 'void loop()':
sketch_aug27_standard_and_360_servo:36: error: a function-definition is not allowed here before '{' token
sketch_aug27_standard_and_360_servo:41: error: a function-definition is not allowed here before '{' token
sketch_aug27_standard_and_360_servo:52: error: expected '}' at end of input
a function-definition is not allowed here before '{' token
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
#include <Servo.h>
Servo Ron1; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup()
{
Ron1.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
Ron1.write(91.5); // tell servo to go to position in variable 'pos'
delay(1); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=0; pos-=1) // goes from 180 degrees to 0 degrees
{
Ron1.write(87); // tell servo to go to position in variable 'pos'
delay(65.9); // waits 15ms for the servo to reach the position
}
#include <Servo.h>
Servo Ron2; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup()
{
Ron2.attach(8); // attaches the servo on pin 8 to the servo object
}
void loop()
{
for(pos = 180; pos <= 0; pos += 1) // goes from 0 degrees to 25 degrees
{ // in steps of 1 degree
Ron2.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 1ms for the servo to reach the position
}
for(pos = 50; pos>=0; pos-=1) // goes from 20 degrees to 0 degrees
{
Ron2.write(pos); // tell servo to go to position in variable 'pos'
delay(300); // waits 1ms for the servo to reach the position
}
}