55Views0Replies

Author Options:

Send and read 2 independent serial data's Answered

Hi there!
I am working ona quad copter..
In which I want to control 4 motors by 2 pots.
My problem is I can send and control 2 motors by a pot..
But how do I control other 2?
Wont the serial data of the 2 pots mix up?

I am attaching a sample of my code to montor the inputs and control 2 motors by a pot..


<code>
#include <Servo.h>

Servo myservo;

int pos = 0;
int poth = 2;
void setup()
{
Serial.begin(9600);
myservo.attach(3, 1700, 2400);
while(Serial.available() <= 0) ;
int incomingByte = Serial.read();
if(incomingByte == 115) {
loop();
delay(1000);
}
}

void loop()
{
int vert=analogRead(poth);
int pos = map(vert,0,1023,0,180);
myservo.write(pos);
Serial.println(pos);
delay(1000);
}
<code>


I just cant tell which is which  how can I setup a communication protocol to identify which data is which?

Comments

The forums are retiring in 2021 and are now closed for new topics and comments.