I'm trying to use the slider function in RemoteXY to turn a motor both backwards and forwards. Yet i've only been able to do one way and it seems to only do 1 speed. I want the motor to turn faster the further away the slider button is from the middle of the slider. Slider_01 is for a servo and slider_02 is for the motor. The contraption uses an Arduino UNO connected to a motor shield Rev 3 and an ESP8622.
//////////////////////////////////////////////
// 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__ESP8266_HARDSERIAL_POINT
// RemoteXY connection settings
#define REMOTEXY_SERIAL Serial
#define REMOTEXY_SERIAL_SPEED 115200
#define REMOTEXY_WIFI_SSID "RemoteXY"
#define REMOTEXY_WIFI_PASSWORD "12345678"
#define REMOTEXY_SERVER_PORT 6377
#include <RemoteXY.h>
// RemoteXY GUI configuration
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] = // 35 bytes
{ 255,2,0,0,0,28,0,17,0,0,0,99,1,200,84,1,1,2,0,4,
46,26,147,31,176,40,26,4,9,0,28,84,48,61,26 };
// this structure defines all the variables and events of your control interface
struct {
// input variables
int8_t slider_01; // =-100..100 slider position
int8_t slider_02; // =-100..100 slider position
// other variable
uint8_t connect_flag; // =1 if wire connected, else =0
} RemoteXY;
#pragma pack(pop)
/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////
#include <Servo.h>
Servo myservo;
int directionPin = 12;
int pwmPin = 3;
int brakePin = 9;
void setup()
{
RemoteXY_Init ();
myservo.attach(5);
RemoteXY.slider_01 = 0;
// TODO you setup code
pinMode(directionPin, OUTPUT);
pinMode(pwmPin, OUTPUT);
pinMode(brakePin, OUTPUT);
}
void loop()
{
yield();
RemoteXY_Handler ();
int ms = RemoteXY.slider_01*8+1530;
myservo.writeMicroseconds(ms);
delay(2);
// TODO you loop code
// use the RemoteXY structure for data transfer
// do not call delay(), use instead RemoteXY_delay()
int motor = RemoteXY.slider_02;
if(RemoteXY.slider_02 < 0){
digitalWrite(directionPin, -100);
}
else{
digitalWrite(directionPin, 100);
}
analogWrite(pwmPin, RemoteXY.slider_02);
}