1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- // Define which pins to use for different tasks
- const int rxPinA = 7; // 433MHz RX, Connected to pin 7
- const int ledPin = 17; // The RX LED has a defined Arduino pin
- // This code is only run once at startup
- void setup()
- {
- // Setup mode of each pin that we will use
- pinMode(ledPin, OUTPUT); // Set LED-pin as an output
- pinMode(rxPinA, INPUT);
- // Call the function that configures the interrupts
- cli(); // Clear interrupt
- setup_timer_interrupt();
- sei(); // Enable interrupt
- // Setup the different serial communication channels
- Serial.begin(9600); // Serial monitor (Over USB, when debugging with Arduino)
- Serial1.begin(9600); // HW-UART (To Raspberry)
- }
- extern unsigned long clas_o_x_data;
- // Convert from 12-bit unsigned data to 32-bit signed data
- static int32_t convertToSignedTemp(uint16_t value)
- {
- return ( (value >> 11) == 0 )? value : ((-1 ^ 0xFFF) | value);
- }
- // This code is called over and over again
- void loop()
- {
- static uint16_t width; // Stores the length of the received pulse
- static unsigned long totalRx = 0; // The total number of received pulses
- if ( rcvDeQueue(&width) ) {
- //width = (width / 5) * 4; // 80%
-
- totalRx++; // Increase the total received pulses
- if( nextPulse_clas_o(width) ) {
-
- int16_t value = convertToSignedTemp( clas_o_x_data & 0xFFF );
- uint16_t id = (clas_o_x_data>>12) & 0x007;
-
- char rad[200];
- sprintf(rad,"Id:%u Temp:%d.%d\n",id,value/10,value%10);
- Serial.print(rad);
-
- clas_o_ResetDecoder();
- }
- // Check if the received pulse is within limits for a start-pulse
- /*if ( 3400 <= width && width <= 3800 ) {
- Serial.print("Received one ! Total pulses: ");
- Serial.println(totalRx);
- }*/
- }
- }
|