code help please

I am working with two 28BYJ-48 Stepper Motors with ULN2003 driver, Arduino Uno and three momentary button switches...

#include <AccelStepper.h>
#define HALFSTEP 8

const int RESET_PIN = A0;
const int BLACK_BUTTON_PIN = A2;
const int RED_BUTTON_PIN = A3;
const int UP_DOWN_MOTOR_PIN_1 = 6;
const int UP_DOWN_MOTOR_PIN_2 = 7;
const int UP_DOWN_MOTOR_PIN_3 = 8;
const int UP_DOWN_MOTOR_PIN_4 = 9;
const int DRIVE_MOTOR_PIN_1 = 2;
const int DRIVE_MOTOR_PIN_2 = 3;
const int DRIVE_MOTOR_PIN_3 = 4;
const int DRIVE_MOTOR_PIN_4 = 5;

//the order in which things happen:

When the black button, (a momentary switch), is depressed;
first the up_down motor rotates about 13 degrees clockwise.
When the rotation is complete, the drive motor will begin it's 180
degree sweep counter clockwise

When the red button, (a momentary switch), is depressed the drive motor
will sweep 180 degrees clockwise...
if the red button is depressed a second time the motor will sweep 180
degrees counterwise; ad infinitum or
allowing the next page to be engaged.

When the reset button, (a momentary switch), is depressed, the updown
will rotate counter clockwise in order to raise
the cam to the starting position.

I have the numbers for set speed, steps to move, etc and can plug them in when the code is there.

That is an incomplete sketch. Have you done more? Have you used any of the stepper tutorials to actually make your stepper motors move?

I am wanting to re-write code because of a change in hardware...I did the same thing previously using one step motor and one servo. For the original rendition I read tutorials and had help from a friend who is also a software engineer.

I'm not a programmer, just a novice. What in particular is missing?

Also, I changed to accelstepper library...I might be able to dig up my sketch from the servo/ step combination. I know the commands, etc,...but, I don't know the c++ environment

bbishop:
What in particular is missing?

Sketches usually have a setup and loop function.
Have you looked at what you posted?

The set up and loop functions, etc....are what I need help with -

here is the code that worked...then I added a reset button, switched the servo for a second stepper...

#include <Servo.h>
#include <Stepper.h>

const int BLACK_BUTTON_PIN = A2;
const int RED_BUTTON_PIN = A3;
const int UP_DOWN_MOTOR_PIN = 10;
const int DRIVE_MOTOR_PIN_1 = 2;
const int DRIVE_MOTOR_PIN_2 = 3;
const int DRIVE_MOTOR_PIN_3 = 4;
const int DRIVE_MOTOR_PIN_4 = 5;

Servo upDownMotor;

int blackButtonValue = 0;
int redButtonValue = 0;
int motorPosition = 0;
;
int redDirection = 0;

void setup() {
  pinMode(BLACK_BUTTON_PIN, INPUT);
  pinMode(RED_BUTTON_PIN, INPUT);
  
  pinMode(DRIVE_MOTOR_PIN_1, OUTPUT);
  pinMode(DRIVE_MOTOR_PIN_2, OUTPUT);
  pinMode(DRIVE_MOTOR_PIN_3, OUTPUT);
  pinMode(DRIVE_MOTOR_PIN_4, OUTPUT);

  upDownMotor.attach(UP_DOWN_MOTOR_PIN);
  
  redDirection = -1;  // -1 means red button goes back, 1 means red button goes forward

  analogReference(DEFAULT);
  delay(500);
}

void loop() {
  // check black button first - value will be 0 - 1023
  blackButtonValue = analogRead(BLACK_BUTTON_PIN);

  // max is 1023, we'll respond to anything greater than 1000
  if (blackButtonValue > 1000)
  {
    // black button means move the motor down one cam and go forward
    // increment the motor position
    motorPosition += 28;
    // move the drive gear down
    upDownMotor.write(motorPosition);
    delay(15);
    
    // turn the page forward
    for (int i = 0; i < 256; i++)
    {
      digitalWrite(DRIVE_MOTOR_PIN_1, HIGH);
      digitalWrite(DRIVE_MOTOR_PIN_2, LOW);
      digitalWrite(DRIVE_MOTOR_PIN_3, LOW);
      digitalWrite(DRIVE_MOTOR_PIN_4, HIGH);
      delay(2);
      digitalWrite(DRIVE_MOTOR_PIN_1, LOW);
      digitalWrite(DRIVE_MOTOR_PIN_2, LOW);
      digitalWrite(DRIVE_MOTOR_PIN_3, HIGH);
      digitalWrite(DRIVE_MOTOR_PIN_4, HIGH);
      delay(2);
      digitalWrite(DRIVE_MOTOR_PIN_1, LOW);
      digitalWrite(DRIVE_MOTOR_PIN_2, HIGH);
      digitalWrite(DRIVE_MOTOR_PIN_3, HIGH);
      digitalWrite(DRIVE_MOTOR_PIN_4, LOW);
      delay(2);
      digitalWrite(DRIVE_MOTOR_PIN_1, HIGH);
      digitalWrite(DRIVE_MOTOR_PIN_2, HIGH);
      digitalWrite(DRIVE_MOTOR_PIN_3, LOW);
      digitalWrite(DRIVE_MOTOR_PIN_4, LOW);
      delay(2);
      digitalWrite(DRIVE_MOTOR_PIN_1, HIGH);
      digitalWrite(DRIVE_MOTOR_PIN_2, LOW);
      digitalWrite(DRIVE_MOTOR_PIN_3, LOW);
      digitalWrite(DRIVE_MOTOR_PIN_4, HIGH);
      delay(2);
      
    }
    
    // red button press after black button press
    // should go backward no matter what
    redDirection = -1;
  }

  // now check red button - value will be 0 - 1023
  redButtonValue = analogRead(RED_BUTTON_PIN);

  // max is 1023, we'll respond to anything greater than 1000
  if (redButtonValue > 1000)
  {
    // red button means go one page in the opposite direction of 
    // the last direction you went in, whatever that was
    if (redDirection > 0)
    {
      for (int i = 0; i < 256; i++)
      {
        digitalWrite(DRIVE_MOTOR_PIN_1, HIGH);
        digitalWrite(DRIVE_MOTOR_PIN_2, LOW);
        digitalWrite(DRIVE_MOTOR_PIN_3, LOW);
        digitalWrite(DRIVE_MOTOR_PIN_4, HIGH);
        delay(2);
        digitalWrite(DRIVE_MOTOR_PIN_1, LOW);
        digitalWrite(DRIVE_MOTOR_PIN_2, LOW);
        digitalWrite(DRIVE_MOTOR_PIN_3, HIGH);
        digitalWrite(DRIVE_MOTOR_PIN_4, HIGH);
        delay(2);
        digitalWrite(DRIVE_MOTOR_PIN_1, LOW);
        digitalWrite(DRIVE_MOTOR_PIN_2, HIGH);
        digitalWrite(DRIVE_MOTOR_PIN_3, HIGH);
        digitalWrite(DRIVE_MOTOR_PIN_4, LOW);
        delay(2);
        digitalWrite(DRIVE_MOTOR_PIN_1, HIGH);
        digitalWrite(DRIVE_MOTOR_PIN_2, HIGH);
        digitalWrite(DRIVE_MOTOR_PIN_3, LOW);
        digitalWrite(DRIVE_MOTOR_PIN_4, LOW);
        delay(2);
        digitalWrite(DRIVE_MOTOR_PIN_1, HIGH);
        digitalWrite(DRIVE_MOTOR_PIN_2, LOW);
        digitalWrite(DRIVE_MOTOR_PIN_3, LOW);
        digitalWrite(DRIVE_MOTOR_PIN_4, HIGH);
        delay(2);
        
      }      
    }
    else
    {
      for (int i = 0; i < 256; i++)
      {
        digitalWrite(DRIVE_MOTOR_PIN_1, HIGH);
        digitalWrite(DRIVE_MOTOR_PIN_2, HIGH);
        digitalWrite(DRIVE_MOTOR_PIN_3, LOW);
        digitalWrite(DRIVE_MOTOR_PIN_4, LOW);
        delay(2);
        digitalWrite(DRIVE_MOTOR_PIN_1, LOW);
        digitalWrite(DRIVE_MOTOR_PIN_2, HIGH);
        digitalWrite(DRIVE_MOTOR_PIN_3, HIGH);
        digitalWrite(DRIVE_MOTOR_PIN_4, LOW);
        delay(2);
        digitalWrite(DRIVE_MOTOR_PIN_1, LOW);
        digitalWrite(DRIVE_MOTOR_PIN_2, LOW);
        digitalWrite(DRIVE_MOTOR_PIN_3, HIGH);
        digitalWrite(DRIVE_MOTOR_PIN_4, HIGH);
        delay(2);
        digitalWrite(DRIVE_MOTOR_PIN_1, HIGH);
        digitalWrite(DRIVE_MOTOR_PIN_2, LOW);
        digitalWrite(DRIVE_MOTOR_PIN_3, LOW);
        digitalWrite(DRIVE_MOTOR_PIN_4, HIGH);
        delay(2);
        digitalWrite(DRIVE_MOTOR_PIN_1, HIGH);
        digitalWrite(DRIVE_MOTOR_PIN_2, HIGH);
        digitalWrite(DRIVE_MOTOR_PIN_3, LOW);
        digitalWrite(DRIVE_MOTOR_PIN_4, LOW);
        delay(2);
        
      }      
    }
    
    // reverse red button motor direction to prepare
    // for a subsequent red button press
    if (redDirection > 0)
    {
      redDirection = -1;
    }
    else
    {
      redDirection = 1;
    }
  }
}

So you're showing us some code that isn't what you're using. You say that you've added a reset button and another stepper motor but for some reason you're not showing us that code.

People round here are good but not good enough to fix what they can't see.

Steve

Apologies for that, I don't know where to begin with changing the code from the standard stepper library to accelstepper, that's why I don't have code to show

bbishop:
here is the code that worked...then I added a reset button, switched the servo for a second stepper...

So what did you add the reset button and stepper to if not to some code? And what has AccelStepper got to do with adding a reset button?

If you mean you added them to the circuit but you haven't even attempted to write any code to use them then say so and stop wasting everyone's time.

Steve

bbishop:
Apologies for that, I don't know where to begin with changing the code from the standard stepper library to accelstepper, that's why I don't have code to show

Go google "arduino accelstepper tutorial"
Try out one of the many, many examples out there. If you run in to problems, let us know.
After you get accelstepper working, try building form there to run your multiple motors.
Try adding buttons to control the different modes you want.