Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <VirtualWire.h> //the same library as before
- 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()
- {
- Serial.begin(9600); //this time, this is important. unity reads from the serial port data
- vw_set_rx_pin(7); //the data pin the receiver is connected to
- Serial.println("Device is ready");
- vw_setup(2000); //bits per sec
- vw_rx_start(); //start the receiver
- }
- void loop()
- {
- if (vw_get_message(message, &messageLength)) //whenever we get a message or messages
- {
- for (int i = 0; i < messageLength; i++) //for each message
- {
- Serial.write(message[i]); //write it to the serial port
- }
- Serial.println(); //and start a new line, ready for the next message
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement