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'.
#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...