Problem with 28BYJ-48

Hi everyone, my name is Gian Luca and i am a newbie in this great world, trying to learn something new everyday and experiment little by little hoping nothing will explode in my face :grinning: :grinning: :grinning:
I was playing with 2 little 28BYJ-48 controlled with a joystick and everything works fine, the 2 motors moves in the direction of the joystick.
I wanted to use 3 push buttons to run only one motor in the right or left position continuously and when the third button is pressed the motor will stop.
I used small_stepper.step(-1) and small_stepper.step(1) to move it to the left or to the right but i don't know how to let it stop pressing the third button.
Hope someone may help me, thank you to all

Please read "How to use this forum" and follow the directions. Explain how things are wired and post your code, using code tags (the "</>" button).

Have you tried:

small_stepper.step(0);

?

Hi to all, sorry for the delay but i was abroad for my job :frowning:
Below you will find the sketch i wrote. I have 3 buttons (Left Right Stop) and it works fine, the stepper moves backward and forward when i push the buttons but stops when i release them. What i need is that the motor runs continuously when i push the button (left or right) and stops with the third button. I'm becaming mad, any help will be appreciated :slight_smile:

// 1 stepper motor controlled by 3 buttons

#include <Stepper.h>

const int stepsPerRevolution = 64;  // change this to fit the number of steps per revolution
// for your motor

                                         
// initialize the stepper library for the stepper
Stepper small_stepper(stepsPerRevolution, 8,10,9,11);  
 
// Initialize buttons
const int RightPin = 2;
const int LeftPin = 3;
const int StopPin = 4;

// variable for reading the pushbuttons
int RightPinState = 0;         
int LeftPinState = 0;
int StopPinState = 0;

void setup() {
 
  small_stepper.setSpeed(500);    // set stepper speed

  pinMode(RightPin, INPUT_PULLUP);
  pinMode(RightPin, INPUT_PULLUP);
  pinMode(StopPin, INPUT_PULLUP);

}


void loop() {
 
  RightPinState = digitalRead(RightPin);
  LeftPinState = digitalRead(LeftPin);
  StopPinState = digitalRead(StopPin);

  if (RightPinState == HIGH) { small_stepper.step(1); }   // step right
  if (LeftPinState == HIGH) { small_stepper.step(-1); }  //  step Left 
  if (StopPinState == HIGH) { small_stepper.step(0); }  //        stop
  
 }

What i need is that the motor runs continuously when i push the button (left or right) and stops with the third button. I'm becaming mad, any help will be appreciated.

Why are you "becaming mad"? The program is doing exactly as you've programmed it to do. If you want it to do something different, you will have to completely redesign the program logic.

Hint: look up and use a State Machine.

For a one dimensional example, in the loop:
Pushing button 1 should make the state variable "moveForward" true.
Pushing button 3 should make the state variable "moveForward" false.
Check state variable moveForward and take appropriate action.

Similarly for state variable "moveReverse".