PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

58 lines
1.3KB

  1. // receiver.pde
  2. //
  3. // Simple example of how to use VirtualWire to receive messages
  4. // Implements a simplex (one-way) receiver with an Rx-B1 module
  5. //
  6. // See VirtualWire.h for detailed API docs
  7. // Author: Mike McCauley (mikem@airspayce.com)
  8. // Copyright (C) 2008 Mike McCauley
  9. // $Id: receiver.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $
  10. #include <VirtualWire.h>
  11. const int led_pin = 13;
  12. const int transmit_pin = 12;
  13. const int receive_pin = 11;
  14. const int transmit_en_pin = 3;
  15. void setup()
  16. {
  17. delay(1000);
  18. Serial.begin(9600); // Debugging only
  19. Serial.println("setup");
  20. // Initialise the IO and ISR
  21. vw_set_tx_pin(transmit_pin);
  22. vw_set_rx_pin(receive_pin);
  23. vw_set_ptt_pin(transmit_en_pin);
  24. vw_set_ptt_inverted(true); // Required for DR3100
  25. vw_setup(2000); // Bits per sec
  26. vw_rx_start(); // Start the receiver PLL running
  27. pinMode(led_pin, OUTPUT);
  28. }
  29. void loop()
  30. {
  31. uint8_t buf[VW_MAX_MESSAGE_LEN];
  32. uint8_t buflen = VW_MAX_MESSAGE_LEN;
  33. if (vw_get_message(buf, &buflen)) // Non-blocking
  34. {
  35. int i;
  36. digitalWrite(led_pin, HIGH); // Flash a light to show received good message
  37. // Message with a good checksum received, dump it.
  38. Serial.print("Got: ");
  39. for (i = 0; i < buflen; i++)
  40. {
  41. Serial.print(buf[i], HEX);
  42. Serial.print(' ');
  43. }
  44. Serial.println();
  45. digitalWrite(led_pin, LOW);
  46. }
  47. }