#include <RH_ASK.h>
#include <VirtualWire.h>
#ifdef RH_HAVE_HARDWARE_SPI
#include <SPI.h>
#endif
// connect data to pin 2
// ( Speed, receving pin , Transmitting pin , push to talk)
RH_ASK driver(2000, 4, 10, 5);
int sw1 = 9;
int sw2 = 7;
int sw3 = 5;
int sw4 = 3;
void setup()
{
#ifdef RH_HAVE_SERIAL
Serial.begin(9600);
#endif
if (!driver.init())
#ifdef RH_HAVE_SERIAL
Serial.println("init failed");
#else
;
#endif
pinMode(sw1,INPUT_PULLUP);
pinMode(sw2,INPUT_PULLUP);
pinMode(sw3,INPUT_PULLUP);
pinMode(sw4,INPUT_PULLUP);
}
void loop()
{
int a = digitalRead(sw1);
int b = digitalRead(sw2);
int c = digitalRead(sw3);
int d = digitalRead(sw4);
if ( a == 0 && b!= 0 && c != 0 && d!=0){
const char *msg = "East";
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
delay(200);
}
else if (a != 0 && b== 0 && c != 0 && d!=0){
const char *msg = "South";
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
delay(200);
}
else if (a != 0 && b!= 0 && c == 0 && d!=0){
const char *msg = "West";
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
delay(200);
}
else if (a != 0 && b!= 0 && c != 0 && d==0){
const char *msg = "North";
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
delay(200);
}
else
{
const char *msg = "Invalid Input";
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
delay(200);
}
}
IDE 2.x is for Problems with the Arduino IDE itself NOT your project. It says so in the description of the section. Therefore I have moved your post here.
You might want to look at this How to get the best out of this forum before you proceed any further.
Also modify your post so that the error message is in the text of your reply and not in the title. Use the pencil icon under your post to exit its text.
Welcome to the forum
Have you by any chance got sketches open in two or more tabs in the IDE ?
Yes
Then that is the likely cause of the problem
If you have more than one .ino file in the sketch folder they each appear on their own tab in the IDE and are combined into a single file when you compile the main sketch
How can I separate it. When I open the main sketch, the other opens with it as well. I am attaching both here
Transmitter.ino (1.48 KB)
Main.ino (5.63 KB)
Put each sketch in its own folder and open multiple instances of the IDE if you want to be able to see and edit either or both of them at the same time
I did that. Now main is fine, but getting error in transmitter file:
C:\Users\hp\AppData\Local\Temp\arduino\sketches\229265BA2AB1B1AB12CFCEA8DE220F97\libraries\Updated-Arduino-VirtualWire-Library-master\VirtualWire.cpp.o (symbol from plugin): In function vw_crc': (.text+0x0): multiple definition of __vector_11'
C:\Users\hp\AppData\Local\Temp\arduino\sketches\229265BA2AB1B1AB12CFCEA8DE220F97\libraries\RadioHead\RH_ASK.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
exit status 1
Compilation error: exit status 1
Here is the complete code:
#include <RH_ASK.h>
#include <VirtualWire.h>
#ifdef RH_HAVE_HARDWARE_SPI
#include <SPI.h>
#endif
// connect data to pin 2
// ( Speed, receving pin , Transmitting pin , push to talk)
RH_ASK driver(2000, 4, 10, 5);
int sw1 = 9;
int sw2 = 7;
int sw3 = 5;
int sw4 = 3;
void setup()
{
#ifdef RH_HAVE_SERIAL
Serial.begin(9600);
#endif
if (!driver.init())
#ifdef RH_HAVE_SERIAL
Serial.println("init failed");
#else
;
#endif
pinMode(sw1,INPUT_PULLUP);
pinMode(sw2,INPUT_PULLUP);
pinMode(sw3,INPUT_PULLUP);
pinMode(sw4,INPUT_PULLUP);
}
void loop()
{
int a = digitalRead(sw1);
int b = digitalRead(sw2);
int c = digitalRead(sw3);
int d = digitalRead(sw4);
if ( a == 0 && b!= 0 && c != 0 && d!=0){
const char *msg = "East";
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
delay(200);
}
else if (a != 0 && b== 0 && c != 0 && d!=0){
const char *msg = "South";
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
delay(200);
}
else if (a != 0 && b!= 0 && c == 0 && d!=0){
const char *msg = "West";
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
delay(200);
}
else if (a != 0 && b!= 0 && c != 0 && d==0){
const char *msg = "North";
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
delay(200);
}
else
{
const char *msg = "Invalid Input";
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
delay(200);
}
}
Two or more libraries are trying to use the same interrupt
Please post the full sketch, using code tags when you do
I have removed the following line, now it is fine:
#include <VirtualWire.h>
Why was it there in the first place ?
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.