Advertisement
AntonioVillanueva

TX 433Mhz arduino test

Sep 8th, 2021 (edited)
536
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.92 KB | None | 0 0
  1. // ask_transmit
  2. //DATA NANO D12
  3. #include <RH_ASK.h>
  4. #include <SPI.h> // Not actually used but needed to compile
  5.  
  6. RH_ASK driver;//Instancia Driver RH_ASK
  7.  
  8. uint8_t cnt=0;
  9. String mensaje="TX";
  10.  
  11. void Debug(char*  txt){
  12.   if (Serial){
  13.      Serial.println (txt);
  14.   }
  15. }
  16.  
  17. void setup()
  18. {
  19.     if (Serial)  
  20.         {Serial.begin(9600);}  // Debug RS232
  21.       else {while (true){};}
  22.      
  23.     if (!driver.init()){
  24.          Debug("TX problem !!!");
  25.     }else { Debug ("TX inicializado ");}
  26.  
  27. }
  28.  
  29. void loop()
  30. {
  31.  
  32.     const char *msg = mensaje.c_str() ;//Mensaje de base
  33.     String num=String (cnt+'\0');
  34.     const char *msg2=num.c_str()+'\0';//Contador
  35.  
  36.     //strcat(msg,msg2);
  37.     driver.send((uint8_t *)msg, strlen(msg)+1);
  38.     driver.waitPacketSent();    
  39.     delay(1000);
  40.     driver.send((uint8_t *)msg2, strlen(msg2)+1);    
  41.     driver.waitPacketSent();
  42.     cnt+=1;
  43.     Debug (msg);
  44.     delay(2000);
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement