Arduino uno with L298n with 2 stepper motors

Hey there I am having issues trying to run 2 L298N motor drivers with stepper motors attached to them and using 4 buttons to control the direction of the motors does anyone have any examples by chance of this to see maybe if I am just missing something in my code.

I hav constantly making the button repeat but never activating in serial monitor.

 /* 
(buttons)
left  pin 5
right pin 4
up    pin 3
back pin 2

(Right Motor)
pin 13 
pin 12
pin 11
pin 10
(Left Motor)
pin 9
pin 8
pin 7
pin 6

*/

#include <Stepper.h>
//Stepper motor1(50, 10, 11, 12, 13);
//Stepper motor2(50, 6, 7, 8, 9);

int motor1pin1 = 10;
int motor1pin2 = 11;
int motor1pin3 = 12;
int motor1pin4 = 13;

int motor2pin1 = 6;
int motor2pin2 = 7;
int motor2pin3 = 8;
int motor2pin4 = 9;


const int BUTTON_PIN_LEFT = 5;
const int BUTTON_PIN_RIGHT = 4;
const int BUTTON_PIN_UP = 3;
const int BUTTON_PIN_DOWN = 2;

int lastState = LOW;  
int currentState; 


void setup()  
{
Serial.begin(9600);
pinMode(BUTTON_PIN_LEFT, INPUT_PULLUP);
pinMode(BUTTON_PIN_RIGHT, INPUT_PULLUP);
pinMode(BUTTON_PIN_UP, INPUT_PULLUP);
pinMode(BUTTON_PIN_DOWN, INPUT_PULLUP);


}

void loop() 
{
int buttonState0 = digitalRead(BUTTON_PIN_LEFT);
  if(lastState == LOW && currentState == HIGH)
     digitalWrite(motor1pin1, HIGH);
     digitalWrite(motor1pin2, LOW);
  delay(1000);
      //digitalWrite(motor1, 50, 10, 11);
  Serial.println("left button is pressed");
  if(lastState == HIGH && currentState == LOW)
  Serial.println("left button is released");
    
int buttonState1 = digitalRead(BUTTON_PIN_RIGHT);
  if(lastState == HIGH && currentState == LOW)
  Serial.println("right button is pressed");
  else if(lastState == LOW && currentState == HIGH)
  Serial.println("right button is released");
    
int buttonState2 = digitalRead(BUTTON_PIN_UP);
  if(lastState == HIGH && currentState == LOW)
  Serial.println("up button is pressed");
  else if(lastState == LOW && currentState == HIGH)
  Serial.println("up button is released");
    
int buttonState3 = digitalRead(BUTTON_PIN_DOWN);
  if(lastState == HIGH && currentState == LOW)
  Serial.println("down button is pressed");
  else if(lastState == LOW && currentState == HIGH)
  Serial.println("down button is released");

Should the commands after this statement be within { } ?

I am not good with word problems. Post a schematic, not a frizzy picture showing all power and ground connections as well. Post links to the technical information on each of the hardware devices. Remember a power supply the Arduino is NOT!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.