Not got a 3 way switch?

I have a Futaba 6EX which has two 2-position switches on channel 5 and 6. I am unable to mix them to form a 4 position switch according the Futaba (marketing or honesty?) so how do I create more positions on my switches?

Why not use an Arduino Pro Mini (already owned) and hook up 3 servo connectors (2 inputs and 1 output) and code it to take in the PWM signal and produce its own in line with the Ardupilot software (Ardupilot Mega in my case). Mental? Please be aware the pulse widths produced are not what APM or AP want they are just so I know if its working.

Here is my code so far:
#include <Servo.h> 
volatile long ch5;    // 1st channel to monitor (in my use channel 5) 
volatile long ch6;    // 2nd channel to monitor (in my use channel 6)
volatile long count1;    // temporary variable for ch5
volatile long count2;    // temporary variable for ch6
volatile int mix1;    // variable for ch5 decision
volatile int mix2;    // variable for ch6 decison
volatile int mix;    // variable for PWM choice
volatile long mixed;    // PWM output length in milliseconds

#define int0 (digitalRead(5))
#define int1 (digitalRead(6))

Servo myServo; 

void ch5interrupt() 

  if(int0)
    count1=micros();        // Positive edge
  else
    ch5=micros()-count1;    // Negative edge: get pulse width


void ch6interrupt()
{
  if(int1)
    count2=micros();
  else
    ch6=micros()-count2;
}

void setup() 

  pinMode(5,INPUT);                // 1st channel input
  pinMode(6,INPUT);                // 2nd channel input
  pinMode(9,OUTPUT);                // Servo output
  attachInterrupt(0,ch5interrupt,CHANGE);    // Any change to pin 5 gets response
  attachInterrupt(0,ch6interrupt,CHANGE);    // Any change to pin 6 gets response
  myServo.attach(9);


void loop() 

  delay(10);

  if (ch5>1500)                //This checks 1st channel value
  {
    mix1 ==3;
  }
  else{
    mix1 ==1;
  }

  if (ch6>1500)                // This checks 2nd channel value
  {
    mix2 ==1;
  }
  else{
    mix2 ==0;
  }

  mix = mix1 + mix2;            // "Mixes" the channels
  if (mix ==1) mixed == 1000;        // Position 1
  if (mix ==2) mixed == 1250;        // Position 2
  if (mix ==3) mixed == 1500;        // Position 3
  if (mix ==4) mixed == 1750;        // Position 4
  myServo.writeMicroseconds(mixed);    // Output PWM of "4-position" switch
}

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • I love this!

  • int pulsewidth_a = APM_RC.InputCh(6);
    int pulsewidth_b = APM_RC.InputCh(7);

    if (pulsewidth_a < 1500 && pulsewidth_b < 1500) pulsewidth == 1300;
    if (pulsewidth_a < 1500 && pulsewidth_b >= 1500) pulsewidth == 1400;
    if (pulsewidth_a >= 1500 && pulsewidth_b < 1500) pulsewidth == 1550;
    if (pulsewidth_a >= 1500 && pulsewidth_b >= 1500) pulsewidth ==1800; //channel 8 (7) will have a PW of 2070

    if (pulsewidth > 1230 && pulsewidth <= 1360) return 2;
    if (pulsewidth > 1360 && pulsewidth <= 1490) return 3;
    if (pulsewidth > 1490 && pulsewidth <= 1620) return 4;
    if (pulsewidth > 1620 && pulsewidth <= 1749) return 5; // Software Manual
    if (pulsewidth >= 1750) return 6; // Hardware Manual
    return 1;


    Is this adequate to produce the 4 position switch as well as maintain hardware failsafe?
  • Developer
    Do I understand that you want to mix two channels into one, but your radio won't do it?
    You could just update the Mega code to do this for you. Piece of cake.


    byte readSwitch(void){

    int pulsewidth = APM_RC.InputCh(4);
    int pulsewidth_b = APM_RC.InputCh(5);
    pulsewidth = /* do some clever maths */

    if (pulsewidth > 1230 && pulsewidth <= 1360) return 2;
    if (pulsewidth > 1360 && pulsewidth <= 1490) return 3;
    if (pulsewidth > 1490 && pulsewidth <= 1620) return 4;
    if (pulsewidth > 1620 && pulsewidth <= 1749) return 5; // Software Manual
    if (pulsewidth >= 1750) return 6; // Hardware Manual
    return 1;
    }
This reply was deleted.

Activity