Here is the code that runs in the cuteduino:
- CODE: SELECT_ALL_CODE
#include <VirtualWire.h>
void setup()
{
// Initialize the IO and ISR
vw_set_tx_pin(0);
vw_setup(2000); // Bits per sec
pinMode(1, INPUT);
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(4, INPUT);
int button = 0;
}
void loop()
{
if (digitalRead(1)) {
send("001");
}
else if (digitalRead(2)) {
send("010");
}
else if (digitalRead(3)) {
send("011");
}
else if (digitalRead(4)) {
send("100");
}
else {
send("000");
}
delay(1000);
}
void send (char *message)
{
vw_send((uint8_t *)message, strlen(message));
vw_wait_tx(); // Wait until the whole message is gone
}
Here is the code at the receiver end:
- CODE: SELECT_ALL_CODE
#include <VirtualWire.h>
byte message[VW_MAX_MESSAGE_LEN]; // a buffer to store the incoming messages
byte messageLength = VW_MAX_MESSAGE_LEN; // the size of the message
void setup()
{
vw_set_rx_pin(A0);
Serial.begin(9600);
Serial.println("Device is ready");
// Initialize the IO and ISR
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver
}
void loop()
{
if (vw_get_message(message, &messageLength)) // Non-blocking
{
Serial.print("Received: ");
for (int i = 0; i < messageLength; i++)
{
Serial.write(message[i]);
}
Serial.println();
}
}