hellow,
I am building a project of painting RF robot.
I got for the robot those compononts:
-servo to put the marker up and down
-motor shield to control the two DC motors that move the robot
-RF reciver that I use the virtualwire library to get the information from
because I need 4 timers to use those components together I got DFRduino mega
but when I try to use the servo library with the virtualWire library it won't compile
and when I use the servotimer2 library with the virtualWire library the reciver doesn't work properly
I would like to know how can I use all these components together?
by the way I add the code for the servotimer2
#include <VirtualWire.h> // you must download and install the VirtualWire.h to your hardware/libraries folder
#include <ServoTimer2.h>ServoTimer2 myservo;
#undef int
#undef abs
#undef double
#undef float
#undef roundint dirA = 13;
int dirB = 12;
int speedA = 10;
int speedB = 9;int mid=1560;
int marker=1520;
int eraser=90;uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;void setup()
{
Serial.begin(9600);// Initialise the IO and ISR
vw_set_ptt_inverted(true); // Required for RX Link Module
vw_setup(2000); // Bits per sec
vw_set_rx_pin(3); // We will be receiving on pin 23 (Mega) ie the RX pin from the module connects to this pin.
vw_rx_start(); // Start the receiverpinMode (dirA, OUTPUT);
pinMode (dirB, OUTPUT);
pinMode (speedA, OUTPUT);
pinMode (speedB, OUTPUT);
digitalWrite (dirA, LOW);
digitalWrite (dirB, LOW);
digitalWrite(speedA, LOW);
digitalWrite(speedB, LOW);myservo.attach(6);
changeServo(0);}
void changeServo(int situ)
{
if (situ==-1){
myservo.write(eraser);
}
if (situ==0){
myservo.write(mid);
}
if (situ==1){
myservo.write(marker);
}
}void loop()
{
vw_wait_rx_max(2000);
if (vw_get_message(buf, &buflen)) // check to see if anything has been received
{Serial.println("here");
Serial.println((int)buf[0]);
Serial.println((int)buf[1]);
Serial.println((int)buf[2]);if (buf[0]%2==0){
digitalWrite (dirA, LOW);
Serial.println("here1");
}
else{
digitalWrite (dirA, HIGH);
Serial.println("here2");
}if (((int)buf[0]/2)%2==0){
digitalWrite (dirB, LOW);
Serial.println("here3");
}
else{
digitalWrite (dirB, HIGH);
Serial.println("here4");
}if (((int)buf[0]/4)%2==0){
changeServo(0);
Serial.println("off");
}
else{
changeServo(1);
Serial.println("on");
}analogWrite (speedA, (int)buf[1]);
Serial.println("here11");
analogWrite (speedB,(int)buf[2]);
Serial.println("here12");}
Serial.println("wait");
}
thanks tomer