Hi,
I'm new to the Arduino forum and have a quick question. I have written some code to read the PWM signal from an rc receiver. See below. As expected the data ranges from 900 to 2000, or 0.9ms to 2.0ms. I would like to run a loop in the arduino if, or when the input value changes by say +- 50 (using the range 900-2000). Is this possible?? I have looked on this great site, but have got confused and bogged down by masses of code and info.
Or maybe it would be possible to just run the code I have previously written when a channel from the transmitter is on i.e. landing gear switch. This would therefore produce an output of either 900 or 2000. 0.9/2ms pwm.
Thanks
int pin = 8; // set this to the pin connected to your receiver ch1
unsigned long duration;
int pin2 = 9; // set this to the pin connected to your receiver ch2
unsigned long duration2;
int pin3 = 10; // set this to the pin connected to your receiver ch3
unsigned long duration3;
void setup()
{
Serial.begin(9600);
pinMode(pin, INPUT);
Serial.begin(9600);
pinMode(pin2, INPUT);
Serial.begin(9600);
pinMode(pin3, INPUT);
}
void loop()
{
duration = pulseIn(pin, HIGH);
Serial.println(duration);
delay(100);
duration2 = pulseIn(pin2, HIGH);
Serial.println(duration2);
delay(100);
duration3 = pulseIn(pin3, HIGH);
Serial.println(duration3);
delay(100);
}