3 simultaneous servos low speed and leds..

Hi.

We are trying to control 3 servos with low speed. We get i with a code like this

void start()
{
 for(int angulo = 0; angulo < 90; angulo += 1) {      
        base.write(angulo);
int inverso = (90-angulo); 
        medio.write(angulo);
        delay(50);}
 }

Now, we want to use the angulo variable to control three actions, like put on a led, for exampe

when 0 < angulo < 30 green led on

when 30 < angulo < 60 red led on

when 60 < angulo < 90 green led off…

¿anybody could help us, please?

Thank you very much!!!

That’s just a very very very tiny piece of your code. We’re not Snippets R Us please upload a working program if you want detailed help.

But next up, what’s wrong with

if(0 < angulo && angulo < 30){
  //do stuff
}

??

except it will not do anything at 0…

Sorry, I thought you prefer only the concrete problem, but… here is the code…

#include <Servo.h>

unsigned  long t0;

Servo base;
Servo medio;
Servo arriba;


void setup() {
  unsigned  long t0;
  base.attach(5);
  medio.attach(6);
  arriba.attach(7);

}

void reposo()
{

base.write(20);
medio.write(180);
arriba.write(0);

}

void start()
{
 for(int angulo = 20; angulo < 65; angulo += 1) {      
        base.write(angulo); 
        delay(50);}
 }
 
void subebase()
{
 for(int angulo = 65; angulo < 115; angulo += 1) {      
   
   
   
   base.write(angulo);
        int inverso = (245-angulo);
        int arriba = (180-inverso);
        medio.write(inverso); 
        delay(50);}
 }

 void bajabase()
{
 for(int angulo = 115; angulo >= 65 ; angulo -= 1) {      
        base.write(angulo); 
        int inverso = (15+angulo);
        int arriba = (80-inverso);
        medio.write(inverso);
        delay(50);}

}
void finish()
{
 for(int angulo = 65; angulo >0 ; angulo -= 1) {      
        base.write(angulo); 
        delay(50);}
 }






void loop(){

reposo();
start();
subebase();
bajabase(); 
subebase();
bajabase(); 
finish();
reposo();
  
 }

That code indents all over the place... Pro tip, press ctrl+T and it will look a lot better.

And my original question remains :slight_smile: