Hello,
I want to rotate a servo and send IR codes at the same time, or first rotate a bit and then send a code.
It seems like the servo can't rotate if the IR led is sending. If i comment out the sending part, the servo works fine.
My goal for this project is to send IR and get RF back (if the IR is pointed in the right direction). I can send and receive everything, but i have to point the IR led by hand and i want to automate that process, therefore i tried using a servo.
I want to make the servo stop when i get a message back (that means that the other arduino received IR).
I tried detaching the servo before sending IR.
My latest iteration of the code:
#include <ServoTimer2.h>
#include <VirtualWire.h>
#include <IRremote.h>
IRsend irsend;
ServoTimer2 servo;
int gotRF=false;
int pos=0;
void setup()
{
Serial.begin(9600);
vw_set_ptt_inverted(true); // Required for DR3100
vw_set_rx_pin(12);
vw_setup(4000); // Bits per sec
pinMode(13, OUTPUT);
vw_rx_start(); // Start the receiver PLL running
servo.attach(5);
}
void loop()
{
for (pos = 750; pos <= 2250; pos += 2) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
servo.write(pos); // tell servo to go to position in variable 'pos'
sendIR();
lookforRF();
}
for (pos = 2250; pos >= 750; pos -= 2) { // goes from 180 degrees to 0 degrees
servo.write(pos); // tell servo to go to position in variable 'pos'
sendIR();
lookforRF();
}
}
void sendIR(){
irsend.sendSony(0x68B92, 20);
delay(10);
}
void lookforRF(){
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
{
if (buf[0] == '1') {
Serial.println("Got: 1");
gotRF=true;
}
}
}
Does anybody know a way to rotate the servo and send IR codes?
Other suggestions for this project are also appreciated.