wireless_temp_sensor_receiver.ino 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Define which pins to use for different tasks
  2. const int rxPinA = 7; // 433MHz RX, Connected to pin 7
  3. const int ledPin = 17; // The RX LED has a defined Arduino pin
  4. // This code is only run once at startup
  5. void setup()
  6. {
  7. // Setup mode of each pin that we will use
  8. pinMode(ledPin, OUTPUT); // Set LED-pin as an output
  9. pinMode(rxPinA, INPUT);
  10. // Call the function that configures the interrupts
  11. cli(); // Clear interrupt
  12. setup_timer_interrupt();
  13. sei(); // Enable interrupt
  14. // Setup the different serial communication channels
  15. Serial.begin(9600); // Serial monitor (Over USB, when debugging with Arduino)
  16. Serial1.begin(9600); // HW-UART (To Raspberry)
  17. }
  18. // This code is called over and oven again
  19. void loop()
  20. {
  21. static uint16_t width; // Stores the length of the received pulse
  22. static unsigned long totalRx = 0; // The total number of received pulses
  23. if ( rcvDeQueue(&width) ) {
  24. totalRx++; // Increase the total received pulses
  25. // Check if the received pulse is within limits for a start-pulse
  26. if ( 3400 <= width && width <= 3800 ) {
  27. Serial.print("Received one ! Total pulses: ");
  28. Serial.println(totalRx);
  29. }
  30. }
  31. }