/*
-- Remote Excavator --
This source code of graphical user interface
has been generated automatically by RemoteXY editor.
To compile this code using RemoteXY library 3.1.13 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.13.13 or later version;
- for iOS 1.10.3 or later version;
This source code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
*/
//////////////////////////////////////////////
// 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__HARDSERIAL
// RemoteXY connection settings
#define REMOTEXY_SERIAL Serial
#define REMOTEXY_SERIAL_SPEED 9600
#include <RemoteXY.h>
// RemoteXY GUI configuration
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] = // 54 bytes
{ 255,5,0,0,0,47,0,17,0,0,0,26,1,200,84,1,1,3,0,5,
1,14,69,69,0,2,28,31,5,130,14,69,69,0,2,28,31,2,78,2,
44,22,0,2,26,31,31,79,78,0,79,70,70,0 };
// this structure defines all the variables and events of your control interface
struct {
// input variables
int8_t joystick_02_x; // from -100 to 100
int8_t joystick_02_y; // from -100 to 100
int8_t joystick_01_x; // from -100 to 100
int8_t joystick_01_y; // from -100 to 100
uint8_t switch_01; // =1 if switch ON and =0 if OFF
// other variable
uint8_t connect_flag; // =1 if wire connected, else =0
} RemoteXY;
#pragma pack(pop)
// INCLUDES
#include <Stepper.h>
// CONSTANTS
const int A_PIN = A0;
const int STEP_PIN_A = 5;
const int DIR_PIN_A = 4;
const int STEPS_PER_REVOLUTION_A = 800;
const int B_PIN = A1;
const int STEP_PIN_B = 8;
const int DIR_PIN_B = 9;
const int STEPS_PER_REVOLUTION_B = 800;
const int C_PIN = A2;
const int STEP_PIN_C = 2;
const int DIR_PIN_C = 3;
const int STEPS_PER_REVOLUTION_C = 800;
const int D_PIN = A3;
const int STEP_PIN_D = 6;
const int DIR_PIN_D = 7;
const int STEPS_PER_REVOLUTION_D = 800;
// VARIABLES
int sensorVal_A, motorSpeed_A;
Stepper myStepper_A = Stepper(STEPS_PER_REVOLUTION_A, STEP_PIN_A, DIR_PIN_A);
int sensorVal_B, motorSpeed_B;
Stepper myStepper_B = Stepper(STEPS_PER_REVOLUTION_B, STEP_PIN_B, DIR_PIN_B);
int sensorVal_C, motorSpeed_C;
Stepper myStepper_C = Stepper(STEPS_PER_REVOLUTION_C, STEP_PIN_C, DIR_PIN_C);
int sensorVal_D, motorSpeed_D;
Stepper myStepper_D = Stepper(STEPS_PER_REVOLUTION_D, STEP_PIN_D, DIR_PIN_D);
void setup() {
RemoteXY_Init ();
}
void loop() {
RemoteXY_Handler ();
sensorVal_A = analogRead(A_PIN); // read Joystick input
// set motor speed accordingly and step the motor
if(sensorVal_A < 470) {
motorSpeed_A = map(sensorVal_A, 0, 470, 60, 0);
myStepper_A.setSpeed(motorSpeed_A);
myStepper_A.step(1);
} else if(sensorVal_A > 550) {
motorSpeed_A = map(sensorVal_A, 550, 1023, 0, 60);
myStepper_A.setSpeed(motorSpeed_A);
myStepper_A.step(-1);
} else motorSpeed_A = 0;
sensorVal_B = analogRead(B_PIN); // read Joystick input
if(sensorVal_B < 470) {
motorSpeed_B = map(sensorVal_B, 0, 470, 60, 0);
myStepper_B.setSpeed(motorSpeed_B);
myStepper_B.step(1);
} else if(sensorVal_B > 550) {
motorSpeed_B = map(sensorVal_B, 550, 1023, 0, 60);
myStepper_B.setSpeed(motorSpeed_B);
myStepper_B.step(-1);
} else motorSpeed_B = 0;
sensorVal_C = analogRead(C_PIN); // read Joystick input
if(sensorVal_C < 470) {
motorSpeed_C = map(sensorVal_C, 0, 470, 60, 0);
myStepper_C.setSpeed(motorSpeed_C);
myStepper_C.step(1);
} else if(sensorVal_C > 550) {
motorSpeed_C = map(sensorVal_C, 550, 1023, 0, 60);
myStepper_C.setSpeed(motorSpeed_C);
myStepper_C.step(-1);
} else motorSpeed_C = 0;
sensorVal_D = analogRead(D_PIN); // read Joystick input
if(sensorVal_D < 470) {
motorSpeed_D = map(sensorVal_D, 0, 470, 60, 0);
myStepper_D.setSpeed(motorSpeed_D);
myStepper_D.step(1);
} else if(sensorVal_D > 550) {
motorSpeed_D = map(sensorVal_D, 550, 1023, 0, 60);
myStepper_D.setSpeed(motorSpeed_D);
myStepper_D.step(-1);
} else motorSpeed_D = 0;
}