Problem with Stepper Library

Hi, I've a problem with the stepper library and i don't know how can i solve it :

So the arduino Board is driving a stepper motor with a rugged board motor driver, this is the code :

#include <StepperHighSpeed.h>
// Define how many steps there are in 1 revolution of your motor
#define STEPS_PER_REVOLUTION 200

#define BOARD  0   /* Arduino Duemilanove/Uno (ATmega328P) */
//#define BOARD  1   /* Arduino Mega (ATmega1280) */
//#define BOARD  2   /* Rugged Circuits Gator (ATmega324P) */

/**********************************************************/
/* YOU SHOULDN'T HAVE TO CHANGE ANYTHING BELOW THIS POINT */
/**********************************************************/
// In case no board is defined, guess from the processor
#ifndef BOARD
#  if defined(__AVR_ATmega328P__)
#    define BOARD 0
#  elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#    define BOARD 1
#  elif defined(__AVR_ATmega324P__)
#    define BOARD 2
#  else
#    error You must define BOARD near the top of this file
#  endif
#endif

#if (BOARD!=0) && (BOARD!=1) && (BOARD!=2)
#error Unknown board
#endif

// Enable (PWM) outputs
#define EN1_PIN 3
#define EN2_PIN 11

// Direction outputs
#define DIR1_PIN 12
#define DIR2_PIN 13

StepperHighSpeed stepper(STEPS_PER_REVOLUTION, DIR1_PIN, DIR2_PIN);
// Set initial default values
unsigned RPM = 180;
unsigned PWM = 230;
unsigned DIR = -1;

void setup()
{
 
  // Configure all outputs off for now
  pinMode(EN1_PIN, OUTPUT); digitalWrite(EN1_PIN, LOW);
  pinMode(EN2_PIN, OUTPUT); digitalWrite(EN2_PIN, LOW);
  pinMode(DIR1_PIN, OUTPUT); digitalWrite(DIR1_PIN, LOW);
  pinMode(DIR2_PIN, OUTPUT); digitalWrite(DIR2_PIN, LOW);


   TCCR2B = _BV(CS21);

  // Now enable PWM and start motion
  analogWrite(EN1_PIN, PWM);
  analogWrite(EN2_PIN, PWM);
  stepper.setSpeed(RPM);
  
}


void loop()
{
// This is a busy-wait loop until the inter-step time passes
 stepper.step(DIR);
}

With this code everything is ok... but...
I need to connect to the same board an infrared sensor that each time that the motor make a 360º, can read-it and send a digital output to another object....

so I'm triyng to insert this code in the master and i've a problem with the void loop ()

#include <StepperHighSpeed.h>
// Define how many steps there are in 1 revolution of your motor
#define STEPS_PER_REVOLUTION 200

#define BOARD  0   /* Arduino Duemilanove/Uno (ATmega328P) */
//#define BOARD  1   /* Arduino Mega (ATmega1280) */
//#define BOARD  2   /* Rugged Circuits Gator (ATmega324P) */

/**********************************************************/
/* YOU SHOULDN'T HAVE TO CHANGE ANYTHING BELOW THIS POINT */
/**********************************************************/
// In case no board is defined, guess from the processor
#ifndef BOARD
#  if defined(__AVR_ATmega328P__)
#    define BOARD 0
#  elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#    define BOARD 1
#  elif defined(__AVR_ATmega324P__)
#    define BOARD 2
#  else
#    error You must define BOARD near the top of this file
#  endif
#endif

#if (BOARD!=0) && (BOARD!=1) && (BOARD!=2)
#error Unknown board
#endif

// Enable (PWM) outputs
#define EN1_PIN 3
#define EN2_PIN 11

// Direction outputs
#define DIR1_PIN 12
#define DIR2_PIN 13

StepperHighSpeed stepper(STEPS_PER_REVOLUTION, DIR1_PIN, DIR2_PIN);
// Set initial default values
unsigned RPM = 180;
unsigned PWM = 230;
unsigned DIR = -1;

// ----------  SETUP FOR TRANSFER SYSTEM ----------------
int ledPin = 2; // LED per inviare segnale alla camera
int inPin = 1;   // Lettura sensore 
int val = 0;     // variable to store the read value
int count = 0;

void setup()
{
 
  // Configure all outputs off for now
  pinMode(EN1_PIN, OUTPUT); digitalWrite(EN1_PIN, LOW);
  pinMode(EN2_PIN, OUTPUT); digitalWrite(EN2_PIN, LOW);
  pinMode(DIR1_PIN, OUTPUT); digitalWrite(DIR1_PIN, LOW);
  pinMode(DIR2_PIN, OUTPUT); digitalWrite(DIR2_PIN, LOW);


   TCCR2B = _BV(CS21);

  // Now enable PWM and start motion
  analogWrite(EN1_PIN, PWM);
  analogWrite(EN2_PIN, PWM);
  stepper.setSpeed(RPM);
  
// --------- SETUP FOR TRANSFER SYSTEM -------------  
pinMode(ledPin, OUTPUT);      // sets the digital pin 2 as output
pinMode(inPin, INPUT);      // sets the digital pin 1 as input

}


void loop()
{
// This is a busy-wait loop until the inter-step time passes
 stepper.step(DIR);
 
 // ---------- LOOP FOR TRIGGER CAMERA ---------
for (int i = 0; i < 1; ++i) {
   // Wait for input to go HIGH
   while (digitalRead (inPin) == LOW) {
   }
   // Wait for input to go LOW
   while (digitalRead (inPin) == HIGH) {
   }
}
digitalWrite (ledPin, HIGH);
delay (150);
digitalWrite (ledPin, LOW); 

// ----------- FINE LOOP FOR TRIGGER CAMERA ------------------
}

I know that maybe is complicate to explain for me, but i don't know how can i create a loop inside the void loop () without the interference to the stepper.step (DIR) function...

Thanks and best

KinoLab

Have a look to see how the blinkWithoutDelay example works for inspiration...

Found the Solution......

this is the final code..

#include <StepperHighSpeed.h>
// Define how many steps there are in 1 revolution of your motor
#define STEPS_PER_REVOLUTION 200

#define BOARD  0   /* Arduino Duemilanove/Uno (ATmega328P) */
//#define BOARD  1   /* Arduino Mega (ATmega1280) */
//#define BOARD  2   /* Rugged Circuits Gator (ATmega324P) */

/**********************************************************/
/* YOU SHOULDN'T HAVE TO CHANGE ANYTHING BELOW THIS POINT */
/**********************************************************/
// In case no board is defined, guess from the processor
#ifndef BOARD
#  if defined(__AVR_ATmega328P__)
#    define BOARD 0
#  elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#    define BOARD 1
#  elif defined(__AVR_ATmega324P__)
#    define BOARD 2
#  else
#    error You must define BOARD near the top of this file
#  endif
#endif

#if (BOARD!=0) && (BOARD!=1) && (BOARD!=2)
#error Unknown board
#endif

// Enable (PWM) outputs
#define EN1_PIN 3
#define EN2_PIN 11

// Direction outputs
#define DIR1_PIN 12
#define DIR2_PIN 13

StepperHighSpeed stepper(STEPS_PER_REVOLUTION, DIR1_PIN, DIR2_PIN);
// Set initial default values
unsigned RPM = 180;
unsigned PWM = 230;
unsigned DIR = -1;

// ---------- PIN FOR TRANSFER ----------------
int ledPin = 10; // LED per inviare segnale alla camera
int inPin = 4;   // Lettura sensore 


void setup()
{
 
  // Configure all outputs off for now
  pinMode(EN1_PIN, OUTPUT); digitalWrite(EN1_PIN, LOW);
  pinMode(EN2_PIN, OUTPUT); digitalWrite(EN2_PIN, LOW);
  pinMode(DIR1_PIN, OUTPUT); digitalWrite(DIR1_PIN, LOW);
  pinMode(DIR2_PIN, OUTPUT); digitalWrite(DIR2_PIN, LOW);


   TCCR2B = _BV(CS21);

  // Now enable PWM and start motion
  analogWrite(EN1_PIN, PWM);
  analogWrite(EN2_PIN, PWM);
  stepper.setSpeed(RPM);
  
// --------- SETUP FOR TRANSFER -------------  
pinMode(ledPin, OUTPUT);      // sets the digital pin 2 as output
pinMode(inPin, INPUT);      // sets the digital pin 1 as input
}


void loop()
{
// This is a busy-wait loop until the inter-step time passes
 stepper.step(DIR);
   
// --------- TRIGGER FOR CAMERA -------------     
    digitalWrite(ledPin, digitalRead(inPin));
}

thanks

Best

KinoLab