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.

56 lines
1.4KB

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