Example 12‐Servo360 controlled by a Joystick - GSTCH/SketchMadeEASY GitHub Wiki

Servo 360°, the rotation speed and direction is controlled by a joystick. If Sketch Made EASY is installed, it can be opened via menu: "File:/Example/SketchMadeEASY/Examples/12-Servo360ControlledByJoystick". A joystick consists of two axis. In Sketch Made EASY these are represented as JoystickAxis. JoystickAxis is like a potentiometer but its value is from minus over 0 to plus. No Inverter is therefore required to change the direction of rotation.

Various types of servo control are availebale. The main reason is a conflict of the timer interrupts, e.g. Log via Serial0 and MotorServoT1 is not possible at the same time. This classes exists:

  • Serv0360T1 (use Interrupt1)
  • Servo360T2 (use Interrupt2).
  • Servo360Pwm (use no interrupt, reconfigure PWM signal, only works with Uno)
  • Servo360I2C (use PWM-Shield over I2C) Below are code examples for these classes.

Servo360T1

Schematic

Code

#include <Easy.h>

//*****************************************************************
#define SERVO360_PIN 10
#define JOYSTICK_AXIS_PIN A10

void setup()
{
  //((*** Initialize: Configure your sketch here....
  //** Define Actuators:
  Actuator* servo360 = new MotorServo360T1(SERVO360_PIN);

  //** Define Input
  Input* xAxis = new JoystickAxis(JOYSTICK_AXIS_PIN, false);

  //** Define logic with condition and relation
  // No condition (NULL) because the relation is always active
  Relation* relationServo = new Relation1to1( NULL, servo360, xAxis );
  // ***))

  // Initialize control
  ControlManagerFactory::GetControlManager()->Setup();
}

//*****************************************************************
void loop() {
  //*** Run: No additional code is required
  ControlManagerFactory::GetControlManager()->Loop();

  // Depending on Arduino it needs a short delay. Do not add any other delays!
  delay(5);
}

Servo360T2

Schematic

Code

#include <Easy.h>

//*****************************************************************
#define SERVO360_PIN 10
#define JOYSTICK_AXIS_PIN A10 

void setup()
{
  //((*** Initialize: Configure your sketch here....
  //** Define Actuators:
  Actuator* servo360 = new MotorServo360T2(SERVO360_PIN);

  //** Define Input
  Input* xAxis = new JoystickAxis(JOYSTICK_AXIS_PIN, false);

  //** Define logic with condition and relation
  // No condition (NULL) because the relation is always active
  Relation* relationServo = new Relation1to1( NULL, servo360, xAxis );
  // ***))

  // Initialize control
  ControlManagerFactory::GetControlManager()->Setup();
}

//*****************************************************************
void loop() {
  //*** Run: No additional code is required
  ControlManagerFactory::GetControlManager()->Loop();

  // Depending on Arduino it needs a short delay. Do not add any other delays!
  delay(5);
}

Servo360Pwm

Schematic

Code

#include <Easy.h>

//*****************************************************************
#define SERVO360_PIN 10
#define JOYSTICK_AXIS_PIN A10 // y=A9, x=A10

void setup()
{
  //((*** Initialize: Configure your sketch here....
  //** Define Actuators:
  Actuator* servo360 = new MotorServo360Pwm(SERVO360_PIN); 

  //** Define Input
  Input* xAxis = new JoystickAxis(JOYSTICK_AXIS_PIN, false);

  //** Define logic with condition and relation
  // No condition (NULL) because the relation is always active
  Relation* relationServo = new Relation1to1( NULL, servo360, xAxis );
  // ***))

  // Initialize control
  ControlManagerFactory::GetControlManager()->Setup();
}

//*****************************************************************
void loop() {
  //*** Run: No additional code is required
  ControlManagerFactory::GetControlManager()->Loop();

  // Depending on Arduino it needs a short delay. Do not add any other delays!
  delay(5);
}

Servo360I2C

Schematic

Code

#include <Easy.h>

//*****************************************************************
#define SERVO360_NR 0
#define JOYSTICK_AXIS_PIN A10 

void setup()
{
  //((*** Initialize: Configure your sketch here....
  //** Define Actuators:
  Actuator* servo360 = new MotorServo360I2C(SERVO360_NR);

  //** Define Input
  Input* xAxis = new JoystickAxis(JOYSTICK_AXIS_PIN, false);

  //** Define logic with condition and relation
  // No condition (NULL) because the relation is always active
  Relation* relationServo = new Relation1to1( NULL, servo360, xAxis );
  // ***))

  // Initialize control
  ControlManagerFactory::GetControlManager()->Setup();
}

//*****************************************************************
void loop() {
  //*** Run: No additional code is required
  ControlManagerFactory::GetControlManager()->Loop();

  // Depending on Arduino it needs a short delay. Do not add any other delays!
  delay(5);
}
⚠️ **GitHub.com Fallback** ⚠️