Example 17‐Servo position in relation to a potentiometer - GSTCH/SketchMadeEASY GitHub Wiki
Servo, the angled is controlled by a potentiometer. If Sketch Made EASY is installed, it can be opened via menu: "File:/Example/SketchMadeEASY/Examples/17-ServoPositionInRelationToPotentiometer".
Various types of servo classes 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:
- Servo360T1 (use Interrupt1)
- Servo360T2 (use Interrupt2).
- ServoPwm (use no interrupt, reconfigure PWM signal, only works with Uno)
- ServoI2C (use PWM-Shield over I2C)
Below are schematic and code examples for these classes.

#include <Easy.h>
//*****************************************************************
// Parameter Servo
#define SERVO_PIN 9
#define SERVO_MIN_ANGLE 0
#define SERVO_MAX_ANGLE 180
// Parameter Potentiometer
#define VARIABLE_INPUT_PIN A0
void setup()
{
//((*** Initialize: Configure your sketch here....
//** Define Actuators:
Actuator* servo = new ServoT1(SERVO_PIN, SERVO_MIN_ANGLE, SERVO_MAX_ANGLE);
//** Define Input
Input* poti = new VariableInput(VARIABLE_INPUT_PIN);
//** Define logic with condition and relation
Relation* relationServo = new Relation1to1( NULL, servo, poti );
// ***))
// 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);
}

#include <Easy.h>
//*****************************************************************
// Parameter Servo
#define SERVO_PIN 9
#define SERVO_MIN_ANGLE 0
#define SERVO_MAX_ANGLE 180
// Parameter Potentiometer
#define VARIABLE_INPUT_PIN A0
void setup()
{
//((*** Initialize: Configure your sketch here....
//** Define Actuators:
ServoT2* servo = new ServoT2(SERVO_PIN, SERVO_MIN_ANGLE, SERVO_MAX_ANGLE);
//** Define Input
VariableInput* poti = new VariableInput(VARIABLE_INPUT_PIN);
//** Define logic with condition and relation
Relation1to1* relationServo = new Relation1to1( NULL, servo, poti );
// ***))
// 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);
}

#include <Easy.h>
//*****************************************************************
// Parameter Servo
#define SERVO_PIN 9
#define SERVO_MIN_ANGLE 0
#define SERVO_MAX_ANGLE 180
// Parameter Potentiometer
#define VARIABLE_INPUT_PIN A0
void setup()
{
//((*** Initialize: Configure your sketch here....
//** Define Actuators:
ServoPwm* servo = new ServoPwm(SERVO_PIN, SERVO_MIN_ANGLE, SERVO_MAX_ANGLE);
//** Define Input
VariableInput* poti = new VariableInput(VARIABLE_INPUT_PIN);
//** Define logic with condition and relation
Relation1to1* relationServo = new Relation1to1( NULL, servo, poti );
// ***))
// 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);
}

#include <Easy.h>
//*****************************************************************
// Parameter Servo
#define SERVO_NUMBER 0
#define SERVO_MIN_ANGLE 0
#define SERVO_MAX_ANGLE 180
// Parameter Potentiometer
#define VARIABLE_INPUT_PIN A0
void setup()
{
//((*** Initialize: Configure your sketch here....
//** Define Actuators:
ServoI2C* servo = new ServoI2C(SERVO_NUMBER, SERVO_MIN_ANGLE, SERVO_MAX_ANGLE);
//** Define Input
VariableInput* poti = new VariableInput(VARIABLE_INPUT_PIN);
//** Define logic with condition and relation
Relation1to1* relationServo = new Relation1to1( NULL, servo, poti );
// ***))
// 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);
}