Essaye mon code peut etre ? je vien de le faire il y a 4 jours ( si problème de libraire )
Tx
#include "VirtualWire.h"
char *msg;
char incomingByte;
void setup() {
Serial.begin(9600);
Serial.println("Initializing radio transmitter..");
vw_setup(2000);
vw_set_tx_pin(12);
checkTx();
delay(200);
Serial.println("done");
}
void loop() {
if (Serial.available() > 0) {
incomingByte = Serial.read();
switch(incomingByte) {
case 'F':
msg = "Forward" ;
vw_send((uint8_t *)msg, strlen(msg));
checkTx();
break;
case 'B':
msg = "Backward";
vw_send((uint8_t *)msg, strlen(msg));
checkTx();
break;
case 'L':
msg = "Left";
vw_send((uint8_t *)msg, strlen(msg));
checkTx();
break;
}
}
Serial.println(incomingByte);
delay(200);
}
void checkTx() {
if (vx_tx_active()) {
Serial.println("Tx is active"); }
else
Serial.println("Tx is not active");
}
Rx
#include "VirtualWire.h"
void setup() {
Serial.begin(9600);
Serial.println("Initializing radio receiver..");
vw_setup(2000);
vw_set_rx_pin(2);
vw_rx_start();
delay(500);
Serial.println("done");
}
void loop() {
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) {
int i;
Serial.print("I receive : ");
for (i=0; i<buflen; i++) {
Serial.write(buf[i]);
}
Serial.println(" ");
}
}