Papermind

receiver

Dec 29th, 2017
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.01 KB | None | 0 0
  1. #include <VirtualWire.h>
  2. const int led_pin = 13;
  3. const int receive_pin = 12;
  4.  
  5. void setup()
  6. {
  7.     Serial.begin(9600);
  8.     Serial.println("Connecting . . . ");
  9.     delay(1000);
  10.     vw_set_rx_pin(receive_pin);
  11.     vw_set_ptt_inverted(true); // Required for DR3100
  12.     vw_setup(2000);  // Bits per sec
  13.     vw_rx_start();       // Start the receiver PLL running
  14.     pinMode(led_pin, OUTPUT);
  15. }
  16. void loop()
  17. {
  18.     uint8_t buf[VW_MAX_MESSAGE_LEN];
  19.     uint8_t buflen = VW_MAX_MESSAGE_LEN;
  20.  
  21. if (vw_get_message(buf, &buflen)) // Non-blocking
  22. { int i;
  23. // lampu akan menyala ketika menerima pesan
  24. digitalWrite(led_pin, HIGH);
  25. // pesan ketika menerima data dari TX
  26.                 Serial.print("Received: ");
  27.                 for (i = 0; i < buflen; i++)                {
  28.                     //menampilkan pesan dalam bentuk karakter
  29.                     Serial.print((char)buf[i]);
  30.                     Serial.print(' ');              }
  31.                     Serial.println();
  32.       digitalWrite(led_pin, LOW);   }}
Add Comment
Please, Sign In to add comment