Hi.
Noob needs some help:(
Im trying to control a stepper whit the arudino lcd shield (6 button)
I whant the stepper to move "clockvise"when i hold "up" button down, and stop if i relese the button.
Same for "down" button but move "counterclockvise"
As im i noob at this im trying to read diffrent tutorials and copy codes in and out to make it work.
Now im stucked:(
Can someone look at this "code"
as you can see i realy dont know mutch about this.
Parts:
Arudino Lcd shield
Arudino Uno
Nema 17 stepper
Easy Motor
ps: i have try the stepper and it works but not in the way i whant whit another code i got online, so wire is good.
Thanks
/David
#define step_pin 3 // Define pin 3 as the steps pin
#define dir_pin 2 // Define pin 2 as the direction pin
#define MS1 5 // Define pin 5 as "MS1"
#define MS2 4 // Define pin 4 as "MS2"
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
int button;
int direction; // Variable to determine the sense of the motor
int steps = 500; // Number of steps that you want to execute (for full steps, 200 = 1 turn)
void setup() {
pinMode(MS1, OUTPUT); // Configures "MS1" as output
pinMode(MS2, OUTPUT); // Configures "MS2" as output
pinMode(dir_pin, OUTPUT); // Configures "dir_pin" as output
pinMode(step_pin, OUTPUT); // Configures "step_pin" as output
pinMode(btnUP, INPUT_PULLUP);
pinMode(btnDOWN, INPUT_PULLUP);
digitalWrite(MS1, LOW); // Configures the steps division (see above)
digitalWrite(MS2, LOW); // Configures the steps division (see above)
digitalWrite(dir_pin, LOW); // Sense (HIGH = anti-clockwise / LOW = clockwise) - It can be also changed
}
void loop() {
if (analogRead(btnUP) == LOW || analogRead(btnDOWN) == LOW) { // ako ni jedan taster nije pritisnut
digitalWrite(step_pin, LOW);
digitalWrite(step_pin, LOW);
}
if (analogRead(btnUP) == LOW && analogRead(btnDOWN) == HIGH) { // ako je taster 1 idle, a taster 2 pritisnut
digitalWrite(dir_pin, LOW); // move in the LOW direction
digitalWrite(step_pin, LOW);
delay(3);
digitalWrite(step_pin, HIGH);
delay(3);
} else if (analogRead(btnUP) == HIGH && (btnDOWN) == LOW) { // ako je taster 2 idle, a taster 1 pritisnut
digitalWrite(dir_pin, HIGH); // move in HIGH direction
digitalWrite(step_pin, LOW);
delay(3);
digitalWrite(step_pin, HIGH);
delay(3);
}
}
int read_buttons() {
int adc_key_in = analogRead(0);
if (adc_key_in > 1000) return btnNONE;
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 195) return btnUP;
if (adc_key_in < 380) return btnDOWN;
if (adc_key_in < 555) return btnLEFT;
if (adc_key_in < 790) return btnSELECT;
}