Topic: Using joystick to control servo motor
Hello guys!
I am stuck into a problem. I want to use a virtual joystick (obviously from RemoteXY) to control the directional angular motion/movement of my servo.
I've tried coding multiple times to get my desired job done. But, every time something is left insignificant or wrong. Therefore I cannot control it through the joystick, how I actually want.
I want to control my servo as:- 1). It should rotate clockwise when I swipe to the positive x-axis of Joystick (exact same for
positive y-axis) and
2). It should rotate anticlockwise when I swipe towards the negative x-axis of the joystick. (exact
same for negative y-axis)
I've attached the servo to Pin No. 13 (All other pins except Analogue ones are already reserved).
The Raw Code of my project (without any interference of mine) is below, please check and improve the same, Please :-
/*
-- New project --
This source code of graphical user interface
has been generated automatically by RemoteXY editor.
To compile this code using RemoteXY library 2.3.3 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.1.1 or later version;
- for iOS 1.2.1 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 //
//////////////////////////////////////////////
// RemoteXY select connection mode and include library
#define REMOTEXY_MODE__ESP8266_HARDSERIAL_POINT
#include <RemoteXY.h>
// Include the Servo library
#include <Servo.h>
// Declare the Servo pin
int servoPin = 13;
// Create a servo object
Servo Servo1;
// RemoteXY connection settings
#define REMOTEXY_SERIAL Serial
#define REMOTEXY_SERIAL_SPEED 115200
#define REMOTEXY_WIFI_SSID "Servo control "
#define REMOTEXY_WIFI_PASSWORD ""
#define REMOTEXY_SERVER_PORT 6377
// RemoteXY configurate
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
{ 255,2,0,0,0,12,0,8,13,0,
5,19,29,7,46,46,2,26,31 };
// this structure defines all the variables of your control interface
struct {
// input variable
int8_t joystick_1_x; // =-100..100 x-coordinate joystick position
int8_t joystick_1_y; // =-100..100 y-coordinate joystick position
// other variable
uint8_t connect_flag; // =1 if wire connected, else =0
} RemoteXY;
#pragma pack(pop)
/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////
void setup()
{
RemoteXY_Init ();
// We need to attach the servo to the used pin number
Servo1.attach(servoPin);
// TODO you setup code
}
void loop()
{
RemoteXY_Handler ();
// I've erased all my garbage from here. So, that you could concentrate easily :D. Thank You So much for taking interest.
// TODO you loop code
// use the RemoteXY structure for data transfer
}
I am a newbie. I love these kind of things and Internet and you people are only teacher of mine in this subject. I learn from you only and I don't have any other means to learn these things. Please please please support and help me. I'll always be grateful to you.
I appreciate your efforts of caring such new children in robotics like me.
Thank You So Much in Advance!!!
Have a nice Day