I'm trying to get my Duemilanove to read two signals from a radio control reciever (Spektrum AR6200) and then transmit it to two servos.
I can't seem to be able to read the incoming signal from the reciever.
I have one channel from the recevier connected to digital pin 5, and one to digital pin 6. I have also established a common GND and then isolated the VCC from the reciever (since I want to use the power from the Duemilanove to power ther servos
This is my code at the moment:
#include <Servo.h>
Servo servo1; // create servo object to control a servo
Servo servo2; // create servo object to control a servo
int iRxIn1 = 5; // input pin for Rx1
int iRxIn2 = 6; // input pin for Rx2
unsigned long lDuration1; // varriable to store the pulse length for Rx1
unsigned long lDuration2; // varriable to store the pulse length for Rx2
int iPosition1 = 0; // variable to store angle for servo1's position
int iPosition2 = 0; // variable to store angle for servo2's postion
void setup()
{
pinMode(iRxIn1, INPUT); // define RxIn1 as an input
pinMode(iRxIn2, INPUT); // define RxIn2 as an input
servo1.attach(9); // attaches the servo on pin 9 to the servo object
servo2.attach(10); // attaches the servo on pin 10 to the servo object
}
void loop()
{
lDuration1 = pulseIn(iRxIn1, HIGH);
lDuration2 = pulseIn(iRxIn2, HIGH);
iPosition1 = map(iRxIn1,1000,2000,0,180);
iPosition2 = map(iRxIn2,1000,2000,0,180);
servo1.write(iPosition1);
servo2.write(iPosition2);
}
Where am I going wrong?