Hi! I posted a while ago asking for help with my RC Dogfighting system. I have since figured out the larger part of that project, but I still need help on some other parts. I already know that it is going to be difficult for me to get IR to work in the sunlight, but please don't bug me about that yet. The problem I am having is that when I have both pwm_value1 and pwm_value2 running at the same time, my servo starts having a bit of lag. It jumps around to the given value every 400 milliseconds or so. If there is a fix for this, I would greatly appreciate the advice. Then there is the problem that when I am transmitting an IR signal, I cannot receive as well. Thanks for the help! Cheers!
#include <IRremote.h>
#include <Servo.h>
const int RECV_PIN = 7;
Servo myservo;
IRrecv irrecv(RECV_PIN);
IRsend irsend;
decode_results results;
byte PWM_PIN1 = 6; // input from recvr gear
byte PWM_PIN2 = 9; // input from rcvr throttle
int pwm_value1;
int pwm_value2;
int potpin = 9;
int val;
void setup(){
Serial.begin(9600);
irrecv.enableIRIn();
irrecv.blink13(true);
pinMode(7, INPUT);
pinMode(9, INPUT);
pinMode(8, INPUT);
pinMode(12, OUTPUT);
myservo.attach(11);
}
void loop(){
pwm_value1 = pulseIn(PWM_PIN1, HIGH);
pwm_value2 = pulseIn(PWM_PIN2, HIGH);
myservo.write(pwm_value2);
Serial.println(pwm_value1);
if (pwm_value1 >= 1300) {
delay(400);
irsend.sendNEC(0xFFF807, 32);
delay(100);
irrecv.enableIRIn();
}
if (irrecv.decode(&results)){
switch(results.value){
case 0xFFF807:
digitalWrite(12, HIGH);
myservo.write(914);
delay(3000);
digitalWrite(12, LOW);
myservo.write(pwm_value2);
}
irrecv.resume();
}
}