I would like to generate a pulse speed in proportion to the resistance values. Say I only want to bump my scope a few steps in a particular direction, or quickly slew across the sky to a new target, I want the stepper speed to be in direct respond to the joystick movemt proportionally.
My current solution works, but not as I envisioned, and for the life of me I cannot seem to visualize a code that achieves my ideal. My current code only uses the joystick movements as indicators of direction (east/west, up/down) and relies on the down switch of the joystick (think Sony PS2 Thumb controller using two variable resistors) to employ the “case” and “break” statements to call different delays between the “on” (HIGH) and “off” (LOW) signals sent to the drivers.
Below is the code I have managed to cobble together I offer up in order to help explain how utterly lost I am.
- Code: Select all
// sketch for driving DIY alt-az
// June, 2018
// define which pins do what
#define step_pinx 2 // D2 is step signal pin for X axis
#define dir_pinx 3 // D3 is direction control pin for X axis
#define x_pin A0 // analog input from joystick for X axis
#define y_pin A1 // analog input from joystick for Y axis
#define joy_switch 6 // joystick switch INPUT PULLUP
#define step_piny 5 // D5 is step signal pin for Y axis
#define dir_piny 4 // D4 is direction control pin for Y axis
int step_speed = 5; // stepper speed higher is slower
void setup() {
delay(1000); // 1 second delay to allow easy drivers to power up
pinMode(joy_switch, INPUT_PULLUP);
pinMode(dir_pinx, OUTPUT);
pinMode(step_pinx, OUTPUT);
pinMode(dir_piny, OUTPUT);
pinMode(step_piny, OUTPUT);
}
void loop() {
//
if (!digitalRead(joy_switch)){ // if joystick switch is clicked
delay(500); // debounce delay
switch(step_speed) { // check speed value and change
case 1:
step_speed=5; // slow
break;
case 3:
step_speed=1; // fast speed
break;
case 10:
step_speed=2.5; // medium speed
break;
}
}
if(analogRead(x_pin)>712){ //if joystick moved left
}
else
digitalWrite(dir_pinx, LOW); // move motor cockwise
digitalWrite(step_pinx, HIGH); //send step signal X axis
delay(step_speed); // delay set by joystick switch case above
digitalWrite(step_pinx, LOW); // stop step signal X axis
delay(step_speed); // set above
if(analogRead(y_pin)>712){ //if joystick moved up
}
else
digitalWrite(dir_piny, LOW); // move motor up
digitalWrite(step_piny, HIGH); //send step signal Y axis
delay(step_speed); // delay set by joystick switch case above
digitalWrite(step_piny, LOW); // stop step signal Y axis
delay(step_speed); // set above
if(analogRead(x_pin)<312){ //if joystick moved right
}
else
digitalWrite(dir_pinx, HIGH); // move motor countercockwise
digitalWrite(step_pinx, HIGH); //send step signal X axis
delay(step_speed); // delay set by joystick switch case above
digitalWrite(step_pinx, LOW); // stop step signal X axis
delay(step_speed); // set above
if(analogRead(y_pin)<312){ // if joystick moved down
}
else
digitalWrite(dir_piny, HIGH); // move motor down
digitalWrite(step_piny, HIGH); //send step signal Y axis
delay(step_speed); // delay set by joystick switch case above
digitalWrite(step_piny, LOW); // stop step signal Y axis
delay(step_speed); // set above
}
Below is what I have built. This is a test to see if the gear trains, all stuff headed to the junk heap, would hold position without power, which it happily does. The only hardware purchased was the up/down shaft bearings and the nuts and bolts holding everything together. My goal here is to mount this to my barn door tracker running from a different Arduino and Easy Driver, and have a 3 axis German Equatorial Mount. After fighting a defective ball head for nearly a year this will provide a much more robust means to lock on to a target. Now if I can only figure out how to make the steppers do things the way I really want.
Thanks all.
RS