Hey all! I just got a new R/C transmitter and receiver... hopefully I get my wheels soon!
This is a very basic how-to use an R/C controller with an arduino... I'm certain there are better ways... especially using interrupts... but this is my first attempt.
Please critique!
/*
Copyright (c) 2013 Richard Pesce. All rights reserved.
This software is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This software is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this software; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Richard Pesce (please give me a little credit)
PesceTech.com
based upon https://www.sparkfun.com/tutorials/348
DX5e transmitter
AR600 reciever
*/
//1100 - 1890 range of motion
//+-10 from center of 1495 to get things going
int thro;
int aile;
int elev;
int rudd;
int gear;
int aux1;
void setup() {
pinMode(A5, INPUT); // Set our input pins as such
pinMode(A4, INPUT);
pinMode(A3, INPUT);
pinMode(A2, INPUT);
pinMode(A1, INPUT);
pinMode(A0, INPUT);
Serial.begin(9600);
}
int rc(){
thro = pulseIn(A5, HIGH, 25000); // Read the pulse width of
aile = pulseIn(A4, HIGH, 25000);
elev = pulseIn(A3, HIGH, 25000);
rudd = pulseIn(A2, HIGH, 25000);
gear = pulseIn(A1, HIGH, 25000);
aux1 = pulseIn(A0, HIGH, 25000);
if (thro < 1480) {
Serial.print("Left stick (moved down): "); // Print the value of
Serial.println(thro); // each channel
}
if (thro > 1510) {
Serial.print("Left stick (moved up): ");
Serial.println(thro);
}
if (aile < 1485) {
Serial.print("Right stick (moved left): ");
Serial.println(aile);
}
if (aile > 1505) {
Serial.print("Right stick (moved right): ");
Serial.println(aile);
}
if (elev < 1485) {
Serial.print("Right stick (moved down): ");
Serial.println(elev);
}
if (elev > 1505) {
Serial.print("Right stick (moved up): ");
Serial.println(elev);
}
if (rudd < 1485) {
Serial.print("Left stick (moved right): ");
Serial.println(rudd);
}
if (rudd > 1505) {
Serial.print("Left stick (moved left): ");
Serial.println(rudd);
}
if (gear < 1495) {
Serial.println("switch up");
}
if (aux1 > 1495) {
Serial.println("toggle switch up");
}
}
void loop() {
rc();
delay(200);
}