system
April 17, 2013, 11:52pm
1
Hi, i recently got this RF kit from ebay and ive got it working so far but im trying to figure out how to turn on LED 13 with this using a push button.
can anyone here help me with the code?
this is the code im using to make it work sending some HEX and i can view it on SERIAL MONITOR
RX - Receiver CODE:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include <VirtualWire.h>
int RF_RX_PIN = 2;
void setup()
{
Serial.begin(9600);
Serial.println("setup");
vw_set_rx_pin(RF_RX_PIN); // Setup receive pin.
vw_setup(2000); // Transmission speed in bits per second.
vw_rx_start(); // Start the PLL receiver.
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if(vw_get_message(buf, &buflen)) // non-blocking I/O
{
int i;
// Message with a good checksum received, dump HEX
Serial.print("Got: ");
for(i = 0; i < buflen; ++i)
{
//Serial.print (buf*, HEX);*
Serial.print(" ");*
_ Serial.print(buf*);_
_ }_
_ Serial.println("");_
_ }_
_ }_
TX - Sender CODE:++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
_ #include <VirtualWire.h>*_
int RF_TX_PIN = 2;
void setup()
{
* pinMode(0,OUTPUT);*
* digitalWrite(0,LOW);*
* pinMode(1,OUTPUT);*
* digitalWrite(1,HIGH);*
* vw_set_tx_pin(RF_TX_PIN); // Setup transmit pin*
* vw_setup(2000); // Transmission speed in bits per second.
_ }*_
void loop()
{
_ const char msg = "ROMNY";_
vw_send((uint8_t )msg, strlen(msg)); // Send 'hello' every 400ms.
vw_wait_tx();
* delay(400);*
}
system
April 18, 2013, 1:14am
2
never mind.... I Found the answer.....
TX:
#include <VirtualWire.h>
int RF_TX_PIN = 2;
void setup()
{
pinMode(0,OUTPUT);
digitalWrite(0,LOW);
pinMode(1,OUTPUT);
digitalWrite(1,HIGH);
vw_set_tx_pin(RF_TX_PIN); // Setup transmit pin
vw_setup(2000); // Transmission speed in bits per second.
pinMode(8, INPUT);
pinMode(9, INPUT);
pinMode(10, INPUT);
pinMode(11, INPUT);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
}
void loop()
{
char *msg;
if(digitalRead(8) == LOW){
char *msg = "1";
digitalWrite(13, true); // Flash a light to show transmitting
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false);}
if(digitalRead(9) == LOW){
char *msg = "2";
digitalWrite(13, true); // Flash a light to show transmitting
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false);}
if(digitalRead(10) == LOW){
char *msg = "3";
digitalWrite(13, true); // Flash a light to show transmitting
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false);}
if(digitalRead(11) == LOW){
char *msg = "4";
digitalWrite(13, true); // Flash a light to show transmitting
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false);}
}
RX:
#include <VirtualWire.h>
int RF_RX_PIN = 2;
void setup()
{
Serial.begin(9600);
Serial.println("setup");
vw_set_rx_pin(RF_RX_PIN); // Setup receive pin.
vw_setup(2000); // Transmission speed in bits per second.
vw_rx_start(); // Start the PLL receiver.
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
}
void loop()
{
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
{
int i;
digitalWrite(13, true); // Flash a light to show received good message
// Message with a good checksum received, dump it.
Serial.print("Got: ");
for (i = 0; i < buflen; i++)
{
Serial.print(buf*);*
_ if(buf == '1'){digitalWrite(8, HIGH);} _
_ if(buf == '2'){digitalWrite(9, HIGH);}
if(buf == '3'){digitalWrite(10, HIGH);}
if(buf == '4'){digitalWrite(11, HIGH);}
* Serial.print(" ");
}
Serial.println("");
digitalWrite(13, false);
}
}[/quote]*_
system
April 18, 2013, 1:24am
3
Now im having this little problem.....
when i push the button the LED would FLASH really quick and its not Bright enough...
im only getting 9.9mV
i guess i have to fix the code IDK...
any idea please???
system
April 18, 2013, 2:04pm
4
any idea please???
Perhaps you should check which pins VirtualWire uses.
if(digitalRead(8) == LOW){
My Arduino does not have a smile face pin. :0