/*
Continuous servo.
myservo.write(0); // full-speed counter-clockwise
myservo.write(90); // stop - approximate, adjust for servo
myservo.write(180); // full-speed clockwise
*/
#include <Servo.h> // servo library
Servo myservo; // create servo object
byte servoPin = 9; // servo signal pin
byte maxCCW = 0, stop = 90, maxCW = 180; // angle definitions
int wait = 20;
#define horz A0
#define vert A1
#define sel 2
void setup() {
Serial.begin(115200); // start serial communication
myservo.attach(servoPin); // attach servo to object
myservo.write(stop); // stop the motor
}
void loop() {
joysticksweep();
// autosweep();
}
void joysticksweep() {
int MAXCCW = 0; // adjust between 90 (STOP) and 0 (fastest CCW)
int MAXCW = 180; // adjust between 90 (STOP) and 180 (fastest CW)
int val = map(analogRead(horz), 0, 1023, MAXCW, MAXCCW);
myservo.write(val);
}
void autosweep() {
sweep(stop, maxCW); // increase CW speed from stop to max
sweep(maxCW, stop); // decrease CW speed from max to stop
sweep(stop, maxCCW); // increase CCW speed from stop to max
sweep(maxCCW, stop); // decrease CCW speed from max to stop
}
void sweep(int a, int b) { // get start and end angle values
if (a < b) {
for (int i = a; i < b; i++) {
myservo.write(i);
delay(wait);
}
} else {
for (int i = a; i > b; i--) {
myservo.write(i);
delay(wait);
}
}
}
CW max speed
CCW max speed
360 servo
stop
360 servo
360 servo
Power
Supply