I am using an arduino uno r4 wifi and the RemoteXY app.
I have two tt motors connected to an H-Bridge driver.
It seems to work fine until I try to go backwards.
/*
-- New project --
To compile this code using RemoteXY library 4.1.8 or later version
download by link http://remotexy.com/en/library/
To connect using RemoteXY mobile app by link http://remotexy.com/en/download/
- for ANDROID 4.18.03 or later version;
- for iOS 1.14.1 or later version;
To interact with the GUI, please refer to the manual:
https://remotexy.com/ru/help/code/interaction/
This source code was automatically generated by the RemoteXY editor and
is an example for the RemoteXY library.
Licensed under the MIT License. See the LICENSE file in the RemoteXY library
root (https://github.com/RemoteXY/RemoteXY-Arduino-library) for full license
details.
*/
//////////////////////////////////////////////
// RemoteXY include library //
//////////////////////////////////////////////
// you can enable debug logging to Serial at 115200
//#define REMOTEXY__DEBUGLOG
// RemoteXY select connection mode and include library
#define REMOTEXY_MODE__WIFI_POINT
#include <WiFiS3.h>
#include <HCSR04.h>
// RemoteXY connection settings
#define REMOTEXY_WIFI_SSID "unor4"
#define REMOTEXY_WIFI_PASSWORD "11111111"
#define REMOTEXY_SERVER_PORT 6377
#include <RemoteXY.h>
// RemoteXY GUI configuration
#pragma pack(push, 1)
uint8_t const PROGMEM RemoteXY_CONF_PROGMEM[] = // 89 bytes V19
{ 255, 3, 0, 4, 0, 82, 0, 19, 0, 0, 0, 0, 31, 1, 106, 200, 1, 1, 5, 0,
5, 5, 90, 95, 95, 32, 2, 26, 31, 129, 3, 52, 56, 12, 64, 24, 104, 101, 97, 100,
108, 105, 103, 104, 116, 115, 0, 10, 66, 42, 32, 32, 48, 4, 26, 31, 79, 78, 0, 31,
79, 70, 70, 0, 67, 253, 13, 107, 13, 78, 2, 26, 2, 129, 2, 15, 38, 10, 64, 2,
100, 105, 115, 116, 97, 110, 99, 101, 0 };
// this structure defines all the variables and events of your control interface
struct {
// input variables
int8_t joystick_01_x; // from -100 to 100
int8_t joystick_01_y; // from -100 to 100
uint8_t pushSwitch_01; // =1 if state is ON, else =0, from 0 to 1
// output variables
float value_01;
// other variable
uint8_t connect_flag; // =1 if wire connected, else =0
} RemoteXY;
#pragma pack(pop)
/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////
UltraSonicDistanceSensor distanceSensor(3, 2); // Initialize sensor that uses digital pins 13 and 12.
unsigned long lastSensorTime = 0;
void setup() {
RemoteXY_Init(); // initialization by macros
pinMode(6, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
// TODO you setup code
digitalWrite(6, 0);
analogWrite(9, 150);
digitalWrite(10, 0);
analogWrite(11, 150);
delay(200);
}
void loop() {
int speed = 0;
int left = 0;
int right = 0;
RemoteXYEngine.handler();
if (!RemoteXY.connect_flag) {
digitalWrite(LED_BUILTIN, 1);
RemoteXYEngine.delay(600);
digitalWrite(LED_BUILTIN, 0);
RemoteXYEngine.delay(600);
}
// sample the HC-SR04 every 60ms
if (millis() - lastSensorTime >= 60) {
RemoteXY.value_01 = 12; //distanceSensor.measureDistanceCm();
digitalWrite(LED_BUILTIN, RemoteXY.pushSwitch_01);
lastSensorTime = millis();
}
if (RemoteXY.joystick_01_y > 50) {
if (RemoteXY.value_01 >= 12) {
if (RemoteXY.joystick_01_y > 90) {
speed = 255;
} else {
speed = 150;
}
}
} else if (RemoteXY.joystick_01_y < -70) {
speed = -150;
}
//
if (RemoteXY.joystick_01_y == 0 && RemoteXY.joystick_01_x == 0) {
digitalWrite(6, 0);
digitalWrite(9, 0);
digitalWrite(10, 0);
digitalWrite(11, 0);
speed = 0;
left = 0;
right = 0;
}
if (RemoteXY.joystick_01_x > 50) {
left = 150;
} else {
left = 0;
}
if (RemoteXY.joystick_01_x < -50) {
right = 150;
} else {
right = 0;
}
if (speed > 1) {//forward
if (RemoteXY.value_01 >= 12) {
digitalWrite(6, 0);
analogWrite(9, min((speed + left), 255));
digitalWrite(10, 0);
analogWrite(11, min((speed + right), 255));
}
} else if (speed < -1) {//back
analogWrite(6, abs(speed));
analogWrite(9, 0);
analogWrite(10, abs(speed));
analogWrite(11, 0);
} else {//still
digitalWrite(6, 0);
analogWrite(9, left);
digitalWrite(10, 0);
analogWrite(11, right);
}
// TODO you loop code
// use the RemoteXY structure for data transfer
// do not call delay(), use instead RemoteXYEngine.delay()
}
int limit(int value) {
if (value > 255) {
value = 255;
}
if (value < 0) {
value = 0;
}
return value;
}
Thanks for the help (i hope it is not a stupid bug
)