Hello @Baozhu! I used this source document avaible on the the 433MHz RF kit (on the page 5):
So I used this code with the RadioHead Library:
#include <RH_ASK.h>
RH_ASK driver;
void setup()
{
initialisation_interruption ();
pinMode(2, INPUT);
digitalWrite(2, HIGH);
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
#ifdef RH_HAVE_SERIAL
Serial.begin(9600);
#endif
if (!driver.init())
#ifdef RH_HAVE_SERIAL
Serial.println("init failed");
#endif
}
void loop()
{
delay (5000);
}
void initialisation_interruption ()
{
attachInterrupt(digitalPinToInterrupt(2), led, CHANGE);
attachInterrupt(digitalPinToInterrupt(11), remote, CHANGE);
}
void led ()
{
if (digitalRead(2))
{
digitalWrite(13, LOW);
}
else if (!digitalRead(2))
{
digitalWrite(13, HIGH);
}
}
void remote ()
{
uint8_t buf[4];
uint8_t buflen = sizeof(buf);
if (driver.recv(buf, &buflen))
{
int i;
Serial.print("Bouton: ");
Serial.println((char*)buf);
}
}
And this code with virtual wire:
#include <VirtualWire.h>
void setup()
{
pinMode(2, INPUT);
digitalWrite(2, HIGH);
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
Serial.begin(9600);
vw_set_rx_pin(3);
vw_setup(2000);
vw_rx_start();
attachInterrupt(digitalPinToInterrupt(2), led, CHANGE);
attachInterrupt(digitalPinToInterrupt(3), remote, CHANGE);
}
void loop()
{
delay (5000);
}
void led ()
{
if (digitalRead(2))
{
digitalWrite(13, LOW);
}
else if (!digitalRead(2))
{
digitalWrite(13, HIGH);
}
}
void remote ()
{
uint8_t buf[4];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen))
{
int i;
Serial.print("Bouton: ");
for (i = 0; i < buflen; i++)
{
Serial.print(buf[i], HEX);
Serial.print(" ");
}
Serial.println("");
digitalWrite(13, false);
}
}
So I need to change the default pin because I need to interrupt my program, I succeeded with this line on Virtual Wire: vw_set_rx_pin(3); but the display looks like this :
Instead of:
Bouton: A
Bouton: B
Bouton: C
Edit: It seems that the lign code to change rx pin is:
RH_ASK driver(2000,3,12,10,false);
or
RH_ASK driver(2000,3);
But it didn’t work