Hi all. Wondering if someone can help/. Ive created the following sketch to use the Arduino joystick for a telescope motor focuser I'm building. It works great, however I'm realising that because I cant see the motor from my hut that I controll the focuser from, I need some visual representation of the speed the focuser (stepper) is running at.
Either:
LED's indicating the speed (low, med or high)
3 buttons (1 for each) that I can press for the required speed.
The part I'm struggling with is how I change the routine for the single button push to 3 independent buttons, or add led's to show the speed highlighted in red below.
Any help you can provide would be greatly appreciated. Feel free to use the sketch below for any project you have.
//Stepper control with Joystick. Coils disable when Joystick centred 24-12-17
#define step_pin 9 // Pin 9 connected to Steps pin on EasyDriver
#define dir_pin 8 // Pin 8 connected to Direction pin
#define MS1 10 // Pin 10 connected to MS1 pin
#define MS2 11 // Pin 11 connected to MS2 pin
#define MENABLE 6 // Pin 6 connected to ENABLE pin
#define X_pin A0 // Pin A0 connected to joystick x axis
#define Joy_switch 4 // Pin 4 connected to joystick switch
int step_speed = 30; // Speed of Stepper motor (higher = slower)
void setup() {
pinMode(MS1, OUTPUT);
pinMode(MS2, OUTPUT);
pinMode(dir_pin, OUTPUT);
pinMode(step_pin, OUTPUT);
pinMode(Joy_switch, INPUT_PULLUP);
pinMode (MENABLE, OUTPUT);
/* Configure type of Steps on EasyDriver:
// MS1 MS2
//
// LOW LOW = Full Step //
// HIGH LOW = Half Step //
// LOW HIGH = A quarter of Step //
// HIGH HIGH = An eighth of Step //
*/
digitalWrite(MS1, LOW); // Configures to Full Steps
digitalWrite(MS2, LOW); // Configures to Full Steps
}
void loop() {
if (!digitalRead(Joy_switch)) { // If Joystick switch is clicked
delay(500); // delay for deboucing
switch (step_speed) { // check current value of step_speed and change it
case 1:
step_speed = 10; // medium speed
break;
case 10:
step_speed = 30; // slow speed
break;
case 30:
step_speed = 1; // fast speed
break;
}
}
if (analogRead(X_pin) > 712) { // If joystick is moved Left
digitalWrite(dir_pin, HIGH); // (HIGH = anti-clockwise / LOW = clockwise)
digitalWrite(step_pin, HIGH);
delay(step_speed);
digitalWrite(step_pin, LOW);
delay(step_speed);
}
if (analogRead(X_pin) < 312) { // If joystick is moved right
digitalWrite(dir_pin, LOW); // (HIGH = anti-clockwise / LOW = clockwise)
digitalWrite(step_pin, HIGH);
delay(step_speed);
digitalWrite(step_pin, LOW);
delay(step_speed);
}
if (analogRead (X_pin) > 320 && analogRead (X_pin) < 700) { // If joystick is centred - being 526
digitalWrite(MENABLE, HIGH); //Pull Enable Pin High
}
else digitalWrite(MENABLE, LOW); //Pull Enable Pin Low
}