Topic: RemoteXY freezes and stops transmitting new data
I am using a joystick to controll the brightness of 3 leds but after a while RemoteXY would stop sending new data to the arduino and would just repeat the latest value the joystick was in. The only way it comes back to normal is when i disconnect it from the bluetooth and reconnect it.
Sometimes it would just stop sending data outright but after a while it comes back to its senses.
Here is my code :
#define REMOTEXY_MODE__HARDSERIAL
#include <RemoteXY.h>
// RemoteXY connection settings
#define REMOTEXY_SERIAL Serial
#define REMOTEXY_SERIAL_SPEED 9600
// RemoteXY configurate
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] = // 64 bytes
{ 255,9,0,21,0,57,0,16,29,0,7,44,27,6,45,7,2,26,2,1,
5,4,4,28,26,26,2,26,31,5,1,71,30,25,25,2,26,31,10,53,
81,1,18,6,4,26,31,79,78,0,31,79,70,70,0,67,4,27,18,45,
7,36,18,21 };
// this structure defines all the variables and events of your control interface
struct {
// input variables
float edit_1;
int8_t joystick_1_x; // from -100 to 100
int8_t joystick_1_y; // from -100 to 100
int8_t joystick_2_x; // from -100 to 100
int8_t joystick_2_y; // from -100 to 100
uint8_t pushSwitch_1; // =1 if state is ON, else =0
// output variables
char text_1[21]; // string UTF8 end zero
// other variable
uint8_t connect_flag; // =1 if wire connected, else =0
} RemoteXY;
#pragma pack(pop)
float directions[10]={0,0,0,0,0,0,0,0,0,0};
unsigned long LT[10]={0,0,0,0,0,0,0,0,0,0};
unsigned long CT = 0;
int Tinterval = 1000;
int YL = 4;
int RL = 3;
int BL = 2;
int walkT = 1;
int walkTR = 0;
int holder;
int dSet;
int check = 0;
int limit;
int lastT;
int k;
int jxPWM;
int jxPWM2;
int jxPWM3;
int human;
bool executed = false;
void turn(int setSwich, int direct);
void go(int setSwich, int mover);
void setCourse(int dArray);
void setup() {
RemoteXY_Init();
pinMode(YL, OUTPUT);
pinMode(RL, OUTPUT);
pinMode(BL, OUTPUT);
Serial.begin(9600);
//Serial.println();
}
void loop(){
RemoteXY_Handler();
if(RemoteXY.edit_1 == 1.66){check = 8;}
if(RemoteXY.edit_1 == 1.1){human = 1;}
if(RemoteXY.edit_1 == 1.2){human = 0;}
if(human == 1){
sprintf (RemoteXY.text_1, "Human Mode");
if(RemoteXY.edit_1 == 1.2){human = 0;}
if(RemoteXY.joystick_1_y > 10){
analogWrite(RL,jxPWM3);
jxPWM3 = -254/-99 * RemoteXY.joystick_1_y +1;
Serial.print("Előre ");
Serial.println(jxPWM3);
}else{analogWrite(RL,0);}
if(RemoteXY.joystick_1_x < -25){
analogWrite(BL,0);
jxPWM = 127/50 * RemoteXY.joystick_1_x *-1 - 155/99 +2;
analogWrite(YL,jxPWM);
Serial.print("Bal ");
Serial.println(jxPWM);
}else{analogWrite(YL,0);}
if(RemoteXY.joystick_1_x >25){
analogWrite(YL,0);
jxPWM2 = -254/-99 * RemoteXY.joystick_1_x +1;
analogWrite(BL,jxPWM2);
Serial.print("Jobb ");
Serial.println(jxPWM2);
}else{analogWrite(BL,0);}
}
if(human == 0){
if(RemoteXY.edit_1 == 1.1){human = 1;}
if(lastT != RemoteXY.edit_1 && check == 0){
directions[0] = RemoteXY.edit_1;
sprintf (RemoteXY.text_1, "okay1");
lastT = RemoteXY.edit_1;
check = 1;}
if(lastT != RemoteXY.edit_1 && check == 1){
directions[1] = RemoteXY.edit_1;
sprintf (RemoteXY.text_1, "okay2");
lastT = RemoteXY.edit_1;
check = 2;}
if(lastT != RemoteXY.edit_1 && check == 2){
directions[2] = RemoteXY.edit_1;
sprintf (RemoteXY.text_1, "okay3");
lastT = RemoteXY.edit_1;
check = 3;}
if(lastT != RemoteXY.edit_1 && check == 3){
directions[3] = RemoteXY.edit_1;
sprintf (RemoteXY.text_1, "okay4");
lastT = RemoteXY.edit_1;
check = 4;}
if(lastT != RemoteXY.edit_1 && check == 4){
directions[4] = RemoteXY.edit_1;
sprintf (RemoteXY.text_1, "okay5");
lastT = RemoteXY.edit_1;
check = 5;}
if(lastT != RemoteXY.edit_1 && check == 5){
directions[5] = RemoteXY.edit_1;
sprintf (RemoteXY.text_1, "okay6");
lastT = RemoteXY.edit_1;
check = 6;}
if(lastT != RemoteXY.edit_1 && check == 6){
directions[6] = RemoteXY.edit_1;
sprintf (RemoteXY.text_1, "okay7");
lastT = RemoteXY.edit_1;
check = 7;}
if(lastT != RemoteXY.edit_1 && check == 7){
directions[7] = RemoteXY.edit_1;
lastT = RemoteXY.edit_1;
sprintf (RemoteXY.text_1, "now turn on");
if(RemoteXY.edit_1 == 1.1){human = 1;}
check = 8;}
if(RemoteXY.pushSwitch_1 == 1){
for(int i = 0;i < 20;i++){
if(i%2 == 0){
switch(walkT){
case 1 :
holder = 1;
go(holder, directions[0]);
break;
case 2 :
holder = 3;
go(holder, directions[2]);
break;
case 4 :
holder = 5;
go(holder, directions[4]);
break;
case 6 :
holder = 7;
go(holder, directions[6]);
break;
}}
if(i&0x01){
switch(walkTR){
case 1 :
holder = 2;
turn(holder,directions[1]);
break;
case 3 :
holder = 4;
turn(holder,directions[3]);
break;
case 5 :
holder = 6;
turn(holder,directions[5]);
break;
case 7 :
holder = 7;
turn(holder,directions[7]);
walkTR = 8;
break;
}
}
}
}
}
}
void turn(int setSwich, int direct)
{ if(direct == 1){
CT = millis();
while(millis() < CT + 2000)
{digitalWrite(BL,LOW);
digitalWrite(YL,HIGH);
}CT = millis();
while(millis() < CT + 2000)
{digitalWrite(BL,LOW);
digitalWrite(YL,LOW);
walkT = setSwich;
}}
if(direct == 2){
CT = millis();
while(millis() < CT + 2000)
{digitalWrite(BL,HIGH);
digitalWrite(YL,LOW);
}CT = millis();
while(millis() < CT + 2000)
{digitalWrite(BL,LOW);
digitalWrite(YL,LOW);
walkT = setSwich;
}}
}
void go(int setSwitch, int mover)
{ CT = millis();
while(millis() < CT + mover)
{digitalWrite(RL,HIGH);
digitalWrite(BL,HIGH);
digitalWrite(YL,HIGH);
}CT = millis();
while(millis() < CT + mover)
{digitalWrite(RL,LOW);
digitalWrite(BL,LOW);
digitalWrite(YL,LOW);
walkTR = setSwitch;
}
}