Ancora grazie Uwe,
la soluzione è stata semplice con la tua dritta (millis)!!!
int step_a_ = 8, off_a_, round_a_, direction_a_, speed_a_;
int step_b_ = 4, off_b_, round_b_, direction_b_, speed_b_;
int a = 10000;
int b = 10000;
unsigned long time=0;
unsigned long stepper_1 =0;
unsigned long stepper_2 =0;
void setup(void)
{
pinMode(step_a_, OUTPUT);
pinMode(step_a_ + 1, OUTPUT);
pinMode(step_a_ + 2, OUTPUT);
pinMode(step_a_ + 3, OUTPUT);
pinMode(step_b_, OUTPUT);
pinMode(step_b_ + 1, OUTPUT);
pinMode(step_b_ + 2, OUTPUT);
pinMode(step_b_ + 3, OUTPUT);
randomSeed(analogRead(0));
}
void loop(void){
if (a > (round_a_ * 200)) {
a = 0, round_a_ = random (1,5), speed_a_ = random(1,5), direction_a_ = random (1,3);
if (direction_a_ == 2) {
direction_a_ = -1;
}
}
if (b > (round_b_ * 48)) {
b = 0, round_b_ = random (1,5), speed_b_ = random(5,8), direction_b_ = random (1,3);
if (direction_b_ == 2) {
direction_b_ = -1;
}
}
time = millis();
stepper_1_treadh();
stepper_2_treadh();
}
void stepper_1_treadh() {
if((stepper_1+speed_a_)<time){
digitalWrite(off_a_,LOW);
step_a_ = step_a_ + direction_a_;
if (step_a_ < 8) step_a_ = 11;
if (step_a_ > 11) step_a_ = 8;
off_a_ = step_a_;
digitalWrite(step_a_,HIGH);
a = a + 1;
stepper_1 = millis();
}
}
void stepper_2_treadh() {
if((stepper_2+speed_b_)<time){
digitalWrite(off_b_,LOW);
step_b_ = step_b_ + direction_b_;
if (step_b_ < 4) step_b_ = 7;
if (step_b_ > 7) step_b_ = 4;
off_b_ = step_b_;
digitalWrite(step_b_,HIGH);
b = b + 1;
stepper_2 = millis();
}
}
Bubz