Advertisement
Guest User

Arduino Gun Receiver Sketch

a guest
Jun 24th, 2016
66
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <VirtualWire.h> //the same library as before
  2.  
  3. byte message[VW_MAX_MESSAGE_LEN]; //a buffer to store the incoming messages
  4. byte messageLength = VW_MAX_MESSAGE_LEN; //the size of the message
  5.  
  6. void setup()
  7. {
  8. Serial.begin(9600); //this time, this is important. unity reads from the serial port data
  9. vw_set_rx_pin(7); //the data pin the receiver is connected to
  10.  
  11. Serial.println("Device is ready");
  12. vw_setup(2000); //bits per sec
  13.  
  14. vw_rx_start(); //start the receiver
  15. }
  16.  
  17. void loop()
  18. {
  19. if (vw_get_message(message, &messageLength)) //whenever we get a message or messages
  20. {
  21. for (int i = 0; i < messageLength; i++) //for each message
  22. {
  23. Serial.write(message[i]); //write it to the serial port
  24. }
  25. Serial.println(); //and start a new line, ready for the next message
  26. }
  27. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement