I apologize ahead of time if i’m posting in the wrong place or if this has already been discussed. This is my first post.
ok, so i have two arduinos with an eb301 bluetooth module attached to each. one arduino has a joystick connected to pins A0 and A1 and it seems to be working right. i see the values change in the serial port and i can connect it to my pc via bluetooth and also see the values change in putty. but on my receiver arduino with the two servos attached, i cant get them to move. the bluetooth modules seem to be paired but what should i change in my code to get it to read the values coming from arduino 1.
here are the codes im using:
Joystick transmitter: arduino 1
int potpin1 = 0;
int potpin2 = 1;
int newval1, oldval1;
int newval2, oldval2;
void setup()
{
Serial.begin(9600);
}
void loop()
{
newval1 = analogRead(potpin1);
newval1 = map(newval1, 0, 1023, 0, 179);
if (newval1 < (oldval1-2) || newval1 > (oldval1+2)){
Serial.println(newval1);
oldval1=newval1;
}
newval2 = analogRead(potpin2);
newval2 = map(newval2, 0, 1023, 0, 179);
if (newval2 < (oldval2-2) || newval2 > (oldval2+2)){
Serial.println(newval2);
oldval2=newval2;
}
delay(50);
}
Joystick receiver: Arduino 2
#include <SoftwareServo.h>
SoftwareServo myservo1;
SoftwareServo myservo2;
int newval1, oldval1;
int newval2, oldval2;
void setup()
{
Serial.begin(9600);
myservo1.attach(12);
myservo2.attach(13);
}
void loop()
{
if( Serial.available() )
{;}
newval1 = Serial.read();
newval1 = map(newval1, 0, 1023, 0, 179);
if (newval1 < (oldval1-2) || newval1 > (oldval1+2)){
myservo1.write(newval1);
oldval1=newval1;
}
newval2 = Serial.read();
newval2 = map(newval2, 0, 1023, 0, 179);
if (newval2 < (oldval2-2) || newval2 > (oldval2+2)){
myservo2.write(newval2);
oldval2=newval2;
}
delay(50);
}
Thank you in advance for any replies and help