void setup()
{
Serial.begin(9600); // Configure the serial connection to the computer
vw_set_ptt_inverted(true); // Required by the RF module
vw_setup(2000); // bps connection speed
vw_set_rx_pin(3); // Arduino pin to connect the receiver data pin
vw_rx_start(); // Start the receiver
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // We check if we have received data
{
int i;
// Message with proper check
for (i = 0; i < buflen; i++)
{
Serial.write(buf*); // The received data is stored in the buffer*
// and sent through the serial port to the computer*
}*
Serial.println();*
if(Serial.read() == ‘H’)*
{*
Serial.flush();*
Serial.print(Serial.available());*
digitalWrite(13, HIGH);*
delay(500);*
digitalWrite(13, LOW);*
delay(500);*
}*
else*
{*
Serial.flush();*
digitalWrite(5, HIGH);*
delay(500);*
digitalWrite(5, LOW);*
delay(500);*
}*
}* } This is our transmitter code. #include <VirtualWire.h> void setup() {
vw_set_ptt_inverted(true); // Required by the RF module*
vw_setup(2000); // bps connection speed*
vw_set_tx_pin(3); // Arduino pin to connect the receiver data pin* } void loop() {
I don't really know I want to get it to work the idea that I clear the buffer but for some reason I may think the the buffer that receives the code and the buffer the normal buffer is different
rochster:
I don't really know I want to get it to work the idea that I clear the buffer but for some reason I may think the the buffer that receives the code and the buffer the normal buffer is different
There are two buffers - one containing data being received and one containing data being sent.
Receiving and sending serial data happens with interrupts, to minimize the impact on your program.
The Serial.print(), Serial.println(), and Serial.write() functions all write to the outgoing buffer, and return immediately, as long as there is room in the outgoing buffer. If not, they block, waiting for there to be room in the buffer.
The Serial.flush() function blocks, waiting for the outgoing buffer to be empty. It has NOTHING to do with the incoming buffer. I can't imagine why you are using the function at all.
If you don't know, stop using it. It isn't doing what you think it does, and makes you look foolish. You don't want that, do you?
PaulS:
There are two buffers - one containing data being received and one containing data being sent.
Is there a command that I can use so that I can read the buffer that is receiving Data?
If so, how is it used and if not any suggestions on what I should do?
Thanks so much for all of your help so far.