// RemoteXY select connection mode and include library
#define REMOTEXY_MODE__ESP8266_HARDSERIAL_POINT
#include <RemoteXY.h>
// RemoteXY connection settings
#define REMOTEXY_SERIAL Serial
#define REMOTEXY_SERIAL_SPEED 115200
#define REMOTEXY_WIFI_SSID "RemoteXY"
#define REMOTEXY_WIFI_PASSWORD "123456789"
#define REMOTEXY_SERVER_PORT 6377
////// 5 Objects --- ON / OFF Button ///////////////////////////////////
// RemoteXY configurate
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] = // 181 bytes
{ 255,3,0,4,0,174,0,16,166,2,4,0,84,7,13,48,47,31,13,63,
2,26,4,0,3,7,13,49,5,32,14,63,2,26,10,48,46,45,10,10,
27,83,10,10,4,26,31,79,78,0,31,79,70,70,0,71,56,52,3,31,
31,33,4,29,29,19,2,24,135,0,0,0,0,0,0,127,67,0,0,72,
66,0,0,72,65,0,0,0,64,24,0,135,0,0,0,0,0,0,220,66,
205,0,0,222,66,0,0,16,67,36,0,0,17,67,0,0,127,67,71,56,
16,3,33,33,1,5,28,28,19,2,24,150,0,0,0,0,0,0,127,67,
0,0,72,66,0,0,72,65,0,0,0,64,24,0,135,0,0,0,0,0,
0,220,66,205,0,0,222,66,0,0,16,67,36,0,0,17,67,0,0,127,
67 };
// this structure defines all the variables and events of your control interface
struct {
// input variables
int8_t slider_1; // =0..100 slider position
int8_t slider_2; // =0..100 slider position
uint8_t pushSwitch_1; // =1 if state is ON, else =0
// output variables
int16_t instrument_1; // from 0 to 255
int16_t instrument_2; // from 0 to 255
// other variable
uint8_t connect_flag; // =1 if wire connected, else =0
} RemoteXY;
#pragma pack(pop)
/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////
///////////////////////// AdaFruit Sheild Definitions //////////////////////////////////////////////////////
// URL : https://lastminuteengineers.com/l293d-motor-driver-shield-arduino-tutorial/
// Include Used Lib (1st Install LIBs from LIB Manager)
#include <AFMotor.h> // Install LIB (Adafruit Motor Shield library)
// Define Which Motor Will be Used
AF_DCMotor motor1(1); // define 1st Motor
AF_DCMotor motor2(2); // define 2nd Motor
////////////////////// Define Servo //////////////////////////////////////////////////////////////////////
#include <Servo.h> // Install LIB (Servo)
Servo servo1; // create servo object to control a servo
int servoPos1 = 0;
int servoDir1 = 1;
int isIncreasing = 1;
void setup()
{
RemoteXY_Init ();
motor1.run(RELEASE); // RELEASE >> Cut Power // FORWARD // BACKWARD
motor2.run(RELEASE); // RELEASE >> Cut Power // FORWARD // BACKWARD
RemoteXY.slider_1 = 50;
RemoteXY.slider_2 = 50;
servoPos1 = 90;
// attaches the servo on pin 10 to the servo object
servo1.attach(10);
servo1.write(servoPos1);
}
void loop()
{
RemoteXY_Handler ();
int s1 = RemoteXY.slider_1 * 2.55;
int s2 = RemoteXY.slider_2 * 2.55;
RemoteXY.instrument_1 = s1;
RemoteXY.instrument_2 = s2;
if (RemoteXY.pushSwitch_1 == 1 ) {
if (s1 > 130) {
motor1.run(FORWARD); // RELEASE >> Cut Power // FORWARD // BACKWARD
motor1.setSpeed(s1); // 0 >> OFF upto 255 >> Full Speed
} else if (s1 < 120) {
motor1.run(BACKWARD); // RELEASE >> Cut Power // FORWARD // BACKWARD
motor1.setSpeed(255 - s1); // 0 >> OFF upto 255 >> Full Speed
} else {
motor1.run(RELEASE); // RELEASE >> Cut Power // FORWARD // BACKWARD
}
if (s2 > 130) {
motor2.run(FORWARD); // RELEASE >> Cut Power // FORWARD // BACKWARD
motor2.setSpeed(s2); // 0 >> OFF upto 255 >> Full Speed
} else if (s2 < 120) {
motor2.run(BACKWARD); // RELEASE >> Cut Power // FORWARD // BACKWARD
motor2.setSpeed(255 - s2); // 0 >> OFF upto 255 >> Full Speed
} else {
motor2.run(RELEASE); // RELEASE >> Cut Power // FORWARD // BACKWARD
}
if(isIncreasing == 1){
if(servoPos1 < 255) servoPos1=servoPos1 + 1;
else isIncreasing = 0;
}
else {
if(servoPos1 > 0) servoPos1=servoPos1 - 1;
else isIncreasing = 1;
}
servo1.write(servoPos1);
RemoteXY_delay(10);
} else {
motor1.run(RELEASE); // RELEASE >> Cut Power // FORWARD // BACKWARD
motor2.run(RELEASE); // RELEASE >> Cut Power // FORWARD // BACKWARD
}
}