Helllo,
I am not programmer, ( beginner at best)
i just make many tries and errors..
i have a 28byj-48 stepper motor
and unl2003 driver
connected in arduino uno the 4 pin in 8,9,10,11, and the pullup button in pin 7,
My idea is to make a motor that by pressing a pull up button will make half rev and in the thes button press will make half but in the opposite direction..
until now this is arduino... i cant understand why it count but it doesnt rotate ?
#define sm1 8
#define sm2 9
#define sm3 10
#define sm4 11
#define button_pin 7
int Pins[] = {sm1,sm2,sm3,sm4};
int button_state = 0;
int button_i = 0;
int prev_button_state = 0;
void setup() {
Serial.begin(9600);
pinMode (button_pin, INPUT_PULLUP);
for (int x=8; x<11; x++){
pinMode(x, OUTPUT);
pinMode (13, OUTPUT);
}
}
void loop() {
button_state = digitalRead(button_pin);
if (button_state != prev_button_state) {
if (button_state == HIGH) {
digitalWrite(13, LOW);
if (button_i % 2 != 0) {
delay(100);
int seq[][4] = {{0,0,0,1},
{0,0,1,0},
{0,1,0,0},
{1,0,0,0}};
for (int x=0; x<256; x++){
for(int step1=0; step1<4; step1++){
for(int pin=0; pin<4; pin++){
digitalWrite(Pins[pin], seq[step1][pin]);
}
delayMicroseconds(25);
}
}
}
else{
delay(100);
int seq[][4] = {{1,0,0,0},
{0,1,0,0},
{0,0,1,0},
{0,0,0,1}};
for (int x=0; x<256; x++){
for(int step1=0; step1<4; step1++){
for(int pin=0; pin<4; pin++){
digitalWrite(Pins[pin], seq[step1][pin]);
}
delayMicroseconds(25);
}
}
}
}else {
digitalWrite(13, HIGH);
button_i++;
Serial.println(button_i);
}
delay(50);
}
prev_button_state = button_state;
}