Hi,
I have got 2 arduinos, a Nano and a Pro Mini, and I am trying to control 2 servos on one arduino from the other. I have one pot. and one basic switch, which I have set to generate a random int between 0 and 1023 when on. These two values are both stored in an array as Tx[0] and Tx[1], I map the values between 0 and 180, then send them over serial with: Serial.write(Tx, 2);
The other arduino then attaches it's servos and reads the serial, and I am trying to get it to store the value in an array called Rx. It then writes to 2 values to the servos.
I have successfully done this with 1 servo and just one integer, but I need to control at least 5 for my project. The problem I have is that I cannot compile my Rx code, I get this error:
error: incompatible types in assignment of 'int' to 'byte [2]'
I think this is a problem with my array and I have little/no experience with C/C++, So i have no idea on how to solve it.
My Tx code is as following:
// MultiServoWiredSerialTx.ino
int Tx[2];
char buf[255];
void setup() {
pinMode(7, OUTPUT);
digitalWrite(7, HIGH);
Serial.begin(38400);
}
void loop() {
Tx[0] = analogRead(0);
if(digitalRead(7) == HIGH){
Tx[1] = random(10, 1023);
} else {
Tx[1] = 0;
}
Tx[0] = map(Tx[0], 0, 1023, 0, 179);
Tx[1] = map(Tx[1], 0, 1023, 0, 179);
Serial.write(Tx, 2);
}
Rx Code:
// MultiServoWiredSerialRx.ino
#include "Servo.h"
byte Rx[2];
Servo servo1;
Servo servo2;
void setup() {
Serial.begin(38400);
servo1.attach(9);
servo2.attach(10);
}
void loop() {
if (Serial.available() > 0) {
Rx = (Serial.read());
}
servo1.write(Rx[0]);
servo2.write(Rx[1]);
}
Thanks.