PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

client.pde 1.4KB

3 jaren geleden
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // client.pde
  2. //
  3. // Simple example of how to use VirtualWire to send and receive messages
  4. // with a DR3100 module.
  5. // Send a message to another arduino running the 'server' example, which
  6. // should send a reply, which we will check
  7. //
  8. // See VirtualWire.h for detailed API docs
  9. // Author: Mike McCauley (mikem@airspayce.com)
  10. // Copyright (C) 2008 Mike McCauley
  11. // $Id: client.pde,v 1.1 2008/04/20 09:24:17 mikem Exp $
  12. #include <VirtualWire.h>
  13. void setup()
  14. {
  15. Serial.begin(9600); // Debugging only
  16. Serial.println("setup");
  17. // Initialise the IO and ISR
  18. vw_set_ptt_inverted(true); // Required for DR3100
  19. vw_setup(2000); // Bits per sec
  20. vw_rx_start(); // Start the receiver PLL running
  21. }
  22. void loop()
  23. {
  24. const char *msg = "hello";
  25. uint8_t buf[VW_MAX_MESSAGE_LEN];
  26. uint8_t buflen = VW_MAX_MESSAGE_LEN;
  27. digitalWrite(13, true); // Flash a light to show transmitting
  28. vw_send((uint8_t *)msg, strlen(msg));
  29. vw_wait_tx(); // Wait until the whole message is gone
  30. Serial.println("Sent");
  31. digitalWrite(13, false);
  32. // Wait at most 200ms for a reply
  33. if (vw_wait_rx_max(200))
  34. {
  35. if (vw_get_message(buf, &buflen)) // Non-blocking
  36. {
  37. int i;
  38. // Message with a good checksum received, dump it.
  39. Serial.print("Got: ");
  40. for (i = 0; i < buflen; i++)
  41. {
  42. Serial.print(buf[i], HEX);
  43. Serial.print(" ");
  44. }
  45. Serial.println("");
  46. }
  47. }
  48. else
  49. Serial.println("Timout");
  50. }