Code Example

/*
  Testing RC Connection
  2/16/16
  Captures the Pulse signal from a RC controller
  Feel free to do whatever you want with this code example
*/
#include <Servo.h>

// Create Variables to hold the Receiver signals
int Ch1, Ch2, Ch3, Ch4, Ch5, Ch6;
int CalcHold;        //Variable to temp hold calculations for steering stick corections
// Set the trigger points away from 0,0 position of the stick
int Ch1_Upper_Trigger = 1525; //Upper Stick setting to start changing right motor speed
int Ch1_Lower_Trigger = 1475; //Lower Stick setting to start changing right motor speed
int Ch2_Upper_Trigger = 1525; //Stick setting to start robot Forward
int Ch2_Lower_Trigger = 1475; //Stick setting to start robot Reverse
// Set the maximum and minimum of the left wheel
int Ch2_Max_Value = 1800; // Max setting above upper threshold
int Ch2_Min_Value = 1200; // Min setting below lower threshold

// Create Servo Objects as defined in the Servo.h files
Servo R_DCMotor;  // Servo DC Motor Driver (Designed for RC cars)
Servo L_DCMotor;  // Servo DC Motor Driver (Designed for RC cars)
//***************************************************************
//******************  Setup  ************************************
//***************************************************************
void setup() {
  // Set the pins that the transmitter will be connected to all to input
  pinMode(12, INPUT); //I connected this to Chan1 of the Receiver
  pinMode(11, INPUT); //I connected this to Chan2 of the Receiver
  pinMode(10, INPUT); //I connected this to Chan3 of the Receiver
  pinMode(9, INPUT); //I connected this to Chan4 of the Receiver
  pinMode(8, INPUT); //I connected this to Chan5 of the Receiver
  pinMode(6, INPUT); //I connected this to Chan6 of the Receiver
  // Attach Speed controller that acts like a servo to the board
  R_DCMotor.attach(1); //Pin 1
  L_DCMotor.attach(0); //Pin 0

  Serial.begin(9600);
}
//***************************************************************
//******************  Main Loop  ********************************
//***************************************************************
void loop()
{
  Ch1 = pulseIn(12, HIGH, 21000);
  Ch2 = pulseIn(11, HIGH, 21000);
  //      Ch3 = pulseIn(10, HIGH, 21000);
  //      Ch4 = pulseIn(9, HIGH, 21000);
  Ch5 = pulseIn(8, HIGH, 21000);
  //      Ch6 = pulseIn(7, HIGH, 21000);

  DriveServosRC(); // Drive Motors under RC control
//    PrintRC(); //Print Values for RC Mode Diagnostics

}