4 servos + remote control

Hello, good morning, im using 4 servos(360°) controles with an ir remite control, could i make a command run and tell it another and stop the previous one ?(for example, go forward all the time until it tells you to go to the right then stop executing the command forward and start the command right and let it do that with everyone), because now it executes a command for a certain period of time and it doesn't matter if I say another one because it doesn't stop.
The code:

#include <Servo.h>
#include <IRremote.h>
#define FORWARD 0x8D0
#define BACKWARD 0x4D0
#define LEFT 0x2F0
#define RIGHT  0xAF0
#define STOP 0xA90
Servo servo_FL;
Servo servo_FR;
Servo servo_BL;
Servo servo_BR;
int pinIr=12;
IRrecv receiver(pinIr);
decode_results results;

void setup() {
  servo_FL.attach(2);
  servo_FR.attach(3);
  servo_BL.attach(4);
  servo_BR.attach(5);
  receiver.enableIRIn();
}

void loop() {
  
 if(receiver.decode(&results)){
   switch(results.value){
      case FORWARD:
        servo_FL.write(0);
        servo_FR.write(180);
        servo_BL.write(0);
        servo_BR.write(180);
        break;
        
      case BACKWARD:
        servo_FL.write(180);
        servo_FR.write(0);
        servo_BL.write(180);
        servo_BR.write(0);
        break;
        
      case RIGHT:
        servo_FL.write(0);
        servo_FR.write(87);
        servo_BL.write(0);
        servo_BR.write(88);
        break;
        
      case LEFT:
        servo_FL.write(81);
        servo_FR.write(180);
        servo_BL.write(72);
        servo_BR.write(180);
        break;
        
      case STOP:
        servo_FL.write(81);
        servo_FR.write(87);
        servo_BL.write(72);
        servo_BR.write(88);
        break;    
  }
  delay(1000);    
  receiver.resume();
 }
 else{      //stop
   servo_FL.write(81);
   servo_FR.write(87);
   servo_BL.write(72);
   servo_BR.write(88);
   delay(40);
   
 }
}

Yes. Your servo commands will stay in effect until you change them. This is the bit of code that stops your motors when no IR command arrives. Remove this part and your car will continue moving in the same way until it receives a new command.

1 Like

it's true, I'm dumb,thanks dude i was looking for solutions and it was that

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