Control servo motor and brushless motor

0

I have a nano Arduino and need to move two components via bluetooth: a servo motor and a brushless motor.

In the Android app, step two variables: one for port 4 and one for port 5. On port 4 is Servo motor and on port 5 is the brushless motor.

I've tried every way and I can not move them.

Here is the Arduino code:

#include <Servo.h>  

Servo myservo;  

int val;  

Servo esc;

int ledPin = 3;        

int value = -1;

void setup()  
{  
  //Pino de dados do servo ligado na porta 4  
  myservo.attach(4);  
  Serial.begin(9600);
  //Pino de dados brushless ligado na porta 5    
  esc.attach(5);
  pinMode(ledPin, OUTPUT);
}  

void loop(){
int key=Serial.read();  
int val=Serial.read(); 

if(val==4){ 
   if(Serial.available()>=2){  
      myservo.write(val);  
  }
}

if(val==5){   
  while (Serial.available()) {
    value = Serial.read();

    if (value >= 0) {

     Serial.println(value); 
     analogWrite(ledPin,value); 
     esc.write(value);
     value = -1;  
     }  
    }
  }
}
    
asked by anonymous 29.09.2018 / 16:32

0 answers