Example 16‐EncoderMotor and LED controlled by FlySky FS‐i6X‐RemoteControl - GSTCH/SketchMadeEASY GitHub Wiki

This example use three channel of the FlySky-RemoteControl. A joystick-axis to control the speed of a encoder motor and a switch-channel to turn a lamp on and off. The channel VrA controls the brightness of the LED If Sketch Made EASY is installed, it can be opened via menu: "File:/Example/SketchMadeEASY/Examples/16-EncoderMotorAndLedControlledByFlySky".

Schematic

Code

L9110

#include <Easy.h>

//*****************************************************************
// Parameter MotorShield L9110
#define MOTOR_PINA1 44
#define MOTOR_PINB1 46
#define MOTOR_PINA2 11
#define MOTOR_PINB2 12
// Parameter Rotary Encoder
#define ENCA 3 // (use a interrupt when RISING, read doc to attachInterupt() to get usable pins)
#define ENCB 4
// Motor N20, n=100m 6V
#define MOTOR_RPM_MAX 60
#define PPR 7
#define GEAR_RATIO 150
// Parameter of LED
#define LED_PIN 6

void setup()
{
   //((*** Initialize: Configure your sketch here....
  //** Define motor controlled by Axis-Joystick of RemoteControl
  //* Create actuator: Encoder gear motor 
  Actuator* encoderMotor = new EncoderMotorL9110(MOTOR_PINA2, MOTOR_PINB2, ENCA, ENCB, PPR, GEAR_RATIO, 0);

  //* Create input: Input is at RemoteControl FlySky  
  RemoteControl* flySky = new FlySky(scHard2);

  //* Define logic with condition and relation
  Relation* relationMotor = new Relation1to1(NULL, encoderMotor, flySky->getControl(rcJoystick1X));

  //** Define LED controlled by a switch at RC 
  //* Create actuator: LED
  Actuator* led = new DigitalOutput(LED_PIN);

  //* Define logic with condition and relation
  // Switch is on, brightness with a Poti on the RC, direct assignement without variable of the RC inputs.
  Condition* conditionSwitchOn = new CompareCondition(flySky->getControl(rcSwA), OpEQ, RemoteValue::Pos1);
  Relation* switchOnRelation = new Relation1to1(conditionSwitchOn, led, flySky->getControl(rcVrA));

  // Switch is off
  Condition* conditionSwitchOff = new CompareCondition(flySky->getControl(rcSwA), OpEQ, RemoteValue::Pos0);
  Relation* switchOffRelation = new Relation1to1(conditionSwitchOff, led, FixValue::Off());
  // ***))

  // 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** ⚠️