Event execution according to the procedure

Good morning~~(this place time 7:20 am)

I have some problem
But I don't know how to solve this problem

void step(boolean dir,int steps)
{
  digitalWrite(dirPin1,dir);
  digitalWrite(dirPin2,dir);
  delay(500);
  for(int i=0;i<steps;i++){
    digitalWrite(stepperPin1, HIGH);
    digitalWrite(stepperPin2, HIGH);
    digitalWrite(stepperPin1, LOW);
    digitalWrite(stepperPin2, LOW);
    delayMicroseconds(200);
  }
} 

void loop()
{
  //cicle count
  step(true,1600*5);
  //right , left cicle delay
  //cicle count
  step(false,1600*5);
  //right , left cicle delay
  
  float x = theta;
  theta += 0.005;
  
  r = (1+sin(x))*127;
  x+=dx;
  Serial.println(theta);

In this code
After step() function started, float theta is added 0.005
But I want add 0.005 in theta in real time
Please help me..
How do i do?

It is only a part of the sketch, so I don't know what the variable 'theta' is for. Can you tell us what you want to do ? I don't understand what you mean with 'real time'.

Do you know the Stepper library : http://arduino.cc/en/reference/stepper
There is also a CustomStepper : Arduino Playground - CustomStepper
And a AccelStepper : AccelStepper: AccelStepper library for Arduino

Oops!!
surry

this is full code

#include <PololuLedStrip.h>

// Create an ledStrip object and specify the pin it will use.
PololuLedStrip<12> ledStrip;

// Create a buffer for holding the colors (3 bytes per color).
#define LED_COUNT 60
rgb_color colors[LED_COUNT];

float amplitude = 75.0;  // Height of wave
float period = 500.0;  // How many pixels before the wave repeats
float g = 0.0;
extern float theta = 0.0;
float dx;  // Value for incrementing X, a function of period and xspacing
float r;

int dirPin1 = 3;
int stepperPin1 = 2;
int dirPin2 = 7;
int stepperPin2 = 6;

long previousMillis = 0;        // will store last time LED was updated

void setup()
{
  Serial.begin(9600);
  
  pinMode(dirPin1, OUTPUT);
  pinMode(stepperPin1, OUTPUT);
  pinMode(dirPin2, OUTPUT);
  pinMode(stepperPin2, OUTPUT);
  dx = (TWO_PI / period);
}

void step(boolean dir,int steps)
{
  digitalWrite(dirPin1,dir);
  digitalWrite(dirPin2,dir);
  delay(500);
  for(int i=0;i<steps;i++){
    digitalWrite(stepperPin1, HIGH);
    digitalWrite(stepperPin2, HIGH);
    delayMicroseconds(100);
    digitalWrite(stepperPin1, LOW);
    digitalWrite(stepperPin2, LOW);
    delayMicroseconds(100);
  }
} 

void loop()
{
  //cicle count
  step(true,1600*5);
  //right , left cicle delay
  //cicle count
  step(false,1600*5);
  //right , left cicle delay
  
  float x = theta;
  theta += 0.005;
  
  r = (1+sin(x))*127;
  x+=dx;
  Serial.println(theta);
  
  rgb_color color;
  color.red = r;
  color.green = r;
  color.blue = r;

  // Update the colors buffer.
  for(uint16_t i = 0; i < LED_COUNT; i++)
  {
    colors[i] = color;
  }
  // Write to the LED strip.
  ledStrip.write(colors, LED_COUNT);
}

In this code
Function of theta is looping price be used bright of led strip
Function of step is control step motor X2

and my purpose is control led strip bright while step motor working

but in this code

step motor -> right rotation( "for(int i=0;i<steps;i++)" ) -> left rotation( "for(int i=0;i<steps;i++)" ) -> theta +0.005...
loop....

so theta add speed is very slow
this problem make me so tired...

extern float theta = 0.0;

Why is theta extern?

and my purpose is control led strip bright while step motor working

That is not going to happen when stepping is done in one function and led control happens in another function.

Oh!! My mistake

this code is edited before 4 hour

now extern is deleted