i have this sketch which moves 3 continous servos at random times and speed. they are continous servos. id like to add 7bit neopixels to turn on when the servos are moving but not sure how to trigger them. this is the code so far.
#include <Servo.h>
Servo myservo1;
Servo myservo2;
Servo myservo3;
int pos = 0;
void setup() {
// The servo control wire is connected to Arduino D2 pin.
myservo1.attach(9);
// Servo is stationary.
myservo1.write(90);
myservo2.attach(10);
// Servo is stationary.
myservo2.write(90);
myservo3.attach(11);
// Servo is stationary.
myservo3.write(90);
}
void loop() {
servo1();
servo2();
servo3();
}
void servo1(){
// Servo spins forward at full speed for 1 second.
myservo1.write(random (140 ,180)); //servo 1 random time position generation in milliseconds);
delay (random( 100 ,500)); //servo 1 random time position generation in milliseconds);
// Servo is stationary for 1 second.
myservo1.write(90);
delay(random (1000,5000));
//Servo spins in reverse at full speed for 1 second.
myservo1.write(random (0 ,50));
delay (random( 100,500)); //servo 1 random time position generation in milliseconds);
// Servo is stationary for 1 second.
myservo1.write(90);
//delay(random (100,5000));
}
void servo2(){
// Servo spins forward at full speed for 1 second.
myservo2.write(random (140 ,180)); //servo 1 random time position generation in milliseconds);
delay (random( 100 ,500)); //servo 1 random time position generation in milliseconds);
// Servo is stationary for 1 second.
myservo2.write(90);
delay(random (1000,5000));
//Servo spins in reverse at full speed for 1 second.
myservo2.write(random (0 ,50));
delay (random( 100,500)); //servo 1 random time position generation in milliseconds);
// Servo is stationary for 1 second.
myservo2.write(90);
//delay(random (100,5000));
}
void servo3(){
// Servo spins forward at full speed for 1 second.
myservo3.write(random (140 ,180)); //servo 1 random time position generation in milliseconds);
delay (random( 100 ,500)); //servo 1 random time position generation in milliseconds);
// Servo is stationary for 1 second.
myservo3.write(90);
delay(random (1000,5000));
//Servo spins in reverse at full speed for 1 second.
myservo3.write(random (0 ,50));
delay (random( 100,500)); //servo 1 random time position generation in milliseconds);
// Servo is stationary for 1 second.
myservo3.write(90);
//delay(random (100,5000));
}
```any help on the matter would be appreciated. i tried creating a random number from millis so as not to block the code but that was a bust for my skill set. this is also going onto a nano.