Random movement of servo and adding neo pixels

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.

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

Let's start with the basics

How are the servos and Neopixels powered ?

they are powered from a 5v source

Unlikely to work with both servos and neopixels, interrupts are disabled while writing to the LEDs, the Servo library uses interrupts to generate the signals for the servos.

Its ok chat gpt got me halfway there. Thankyou

Please be aware that code produced by ChatGPT are not highly regarded here as experienced users do not like to waste their time correcting it, so much so that they may even choose to ignore future posts from you

Do you understand what the code that you posted does and how it works ?

To be honest, i kinda understand, but i just uploaded it and it kinda works but i can have a better look tomorrow and try edit to suit my needs.

This forum works best when users post their best effort to write a sketch to meet their needs. If they just post what a bot writes without understanding it then they are unlikely to be able to understand suggested changes

The problem was always there with code copied from the Web but has been exacerbated by the use of bots. I urge you to look at the code closely with a view to understanding it. I find it helpful when looking at someone else's code to imagine that I am explaining it to a third party. You can even pretend to be the third party and ask yourself questions

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.