daily pastebin goal
3%
SHARE
TWEET

Untitled

a guest Mar 22nd, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // .h team code grabber
  2. #include <uCRC16BPBLib.h>
  3. #include <VirtualWire.h>
  4.  
  5. uCRC16BPBLib crc;
  6.  
  7. const int receive_pin = 11;
  8. const int trans_pin = 7;
  9. const int led_pin = 13;
  10. const int transmit_en_pin = 3;
  11. uint8_t hash1, hash2; // for receiver and transmitter
  12. int val; // 0 or 1 bluetooth
  13. uint8_t buf[VW_MAX_MESSAGE_LEN];
  14. uint8_t buflen = VW_MAX_MESSAGE_LEN;
  15.  
  16. void setup()
  17. {
  18.     delay(1000);
  19.     Serial.begin(9600); // Debugging only
  20.     Serial.println("setup");
  21.     vw_set_tx_pin(trans_pin);
  22.     vw_set_rx_pin(receive_pin);
  23.     vw_set_ptt_pin(transmit_en_pin);
  24.     vw_setup(2000);
  25.     vw_rx_start();
  26. }
  27.  
  28. void loop()
  29. {
  30.   if(Serial.available()){
  31.     val = Serial.read(); //for bluetooth hc05
  32.     if(val=='0'){
  33.     crc.reset();
  34.    
  35.     if (vw_get_message(buf, &buflen))
  36.     {
  37.     int i;
  38.  
  39.     Serial.print("HEX: ");
  40.    
  41.     for (i = 0; i < buflen; i++)
  42.     {
  43.         Serial.print(buf[i], HEX);
  44.         Serial.print(' ');
  45.     }
  46.   Serial.print("\nDEC: ");
  47.   for (i = 0; i < buflen; i++)
  48.   {
  49.       Serial.print(buf[i], DEC);
  50.       Serial.print(' ');
  51.   }
  52.   //checksum
  53.   Serial.print("\nCRC16 receiver: ");
  54.    crc.feedByte(buf[1]);
  55.    crc.feedByte(buf[2]);
  56.    crc.feedByte(buf[3]);
  57.    
  58.   Serial.println(crc.getResult(), HEX);
  59.  
  60.   //uint8_t keyword[7];
  61. //  memcpy(buf, keyword, 7);
  62. //  Serial.println(keyword);
  63. //  buf[1] += 174;
  64.    
  65.   }
  66.     }
  67.     if(val=='1'){
  68.  //transmitter
  69.   buf[3] += 100;
  70.   crc.reset();
  71.  Serial.print("\nCRC16 receiver: ");
  72.    crc.feedByte(buf[1]);
  73.    crc.feedByte(buf[2]);
  74.    crc.feedByte(buf[3]);
  75.    hash2 = crc.getResult();
  76.   Serial.println(hash2, HEX);
  77.  
  78.  if(hash1==hash2){
  79.     Serial.print("Sending HEX: ");
  80.     for(int i=0; i < 7; i++)
  81.     {
  82.       Serial.print(buf[i], HEX);
  83.       Serial.print(' ');
  84.     }
  85.     Serial.print("\nSending DEC: ");
  86.     for(int i=0; i < 7; i++){
  87.       Serial.print(buf[i], DEC);
  88.       Serial.print(' ');
  89.     }
  90.     Serial.println();
  91.   digitalWrite(led_pin, HIGH);
  92.  
  93.   vw_send(buf, 7);
  94.   vw_wait_tx(); // Wait until the whole message is gone
  95.   digitalWrite(led_pin, LOW);
  96.     }
  97.   }  //val == 1
  98.   delay(1000);
  99.  } //serial bluetooth
  100. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top