Hey Guys, looking for a bit of help. I want to be able to control a continuous servo incrementally (forward, backwards) with a rotary encoder, as well as a joystick…same motion just different types of control methods…
I’m super new at this, but i somehow managed to piece together a code that seems to work. Problem is when i turn the rotary encoder it feels pretty good in relation with the servo movement, however if i turn it to quick it seems to stutter a bit and get confused for a second. I believe it’s due to the fact that i have no idea what i’m doing and somehow got lucky. I’d like to control the servo with the rotary encoder like it’s 2021 and we somehow merged with robots. I know i may be using the wrong parts for the job. I already have it working with a stepper motor, but i can’t get the feel right. End goal is to use it with a mini linear actuator type device.
Using an SPT6325LV-360 servo:
https://www.amazon.ca/Digital-Continuous-Rotation-Robots-Accessories/dp/B07T7GFRKT/ref=sr_1_7?crid=D94X73UBYK79&dchild=1&keywords=continuous+rotation+servo&qid=1598499541&sprefix=continuous+rotation%2Caps%2C191&sr=8-7
Arduino Uno Board
Here’s the code
#include <Servo.h>
#define inputCLK 4
#define inputDT 5
#define potpin A3
Servo myservo;
int val1;
int counter = 1500;
int currentStateCLK;
int previousStateCLK;
void setup() {
pinMode (inputCLK, INPUT);
pinMode (inputDT, INPUT);
Serial.begin (9600);
myservo.attach(9);
previousStateCLK = digitalRead(inputCLK);
}
void loop() {
counter = 1500;
val1 = analogRead(potpin);
val1 = map(val1, 0, 1023, 1000, 2000);
myservo.write(val1);
//Serial.println(val1);
{
currentStateCLK = digitalRead(inputCLK);
if (currentStateCLK != previousStateCLK) {
if (digitalRead(inputDT) != currentStateCLK) {
counter --;
if (counter = 2000) {
counter = 2000;
}
} else {
counter ++;
if (counter = 1000) {
counter = 1000;
}
}
myservo.writeMicroseconds(counter);
//Serial.print(val);
Serial.println(counter);
delay(25);
}
previousStateCLK = currentStateCLK;
}
}
I feel like i’m a million computer clickity clacks away from solving this issue. If i spend a month on this my girlfriend will probably break up with me…Please help!