SHARE
TWEET

REciever code

a guest Jul 21st, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  //--------Comments--------
  2. //
  3. //  
  4. //    
  5. //  Temp = TempC
  6. //  Hum = Light
  7. //  Light = L
  8. //
  9. //
  10. //------------------------
  11. //--------Libs--------
  12. #include <Arduino.h>
  13. #include <U8g2lib.h>
  14. #include <U8x8lib.h>
  15. #include <Arduino.h>
  16.  
  17. #ifdef U8X8_HAVE_HW_SPI
  18. #include <SPI.h>
  19. #endif
  20.  
  21. #include <nRF24L01.h>
  22. #include <RF24.h>
  23.  
  24. //--------Objects--------
  25. RF24 radio(7 , 8); // CE, CSN
  26. U8G2_SSD1327_MIDAS_128X128_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
  27.  
  28. //--------Integers-------
  29. const byte address[6] = "00001";
  30. int Temp;
  31. int Hum;
  32. int Light;
  33. int LightP;
  34. int Rain;
  35.  
  36. int TempCorrect = 2;       //Correction for the temperature overshoot of the DHT11, usually this is 2 degrees.
  37. //int Pot = A0;
  38. int TempC;                  // Corrected temp;
  39.  
  40. int MaxFails = 6;
  41. int L;
  42.  
  43. int LMin = 30;
  44. int LMax = 135;
  45.  
  46. //bool Dev;
  47. int WrongReadings;
  48. int FailCount;
  49.  
  50.  
  51. //--------Startup--------
  52. void setup() {
  53.  
  54. u8g2.begin();
  55. u8g2.setFont(u8g2_font_ncenB14_tr);
  56. u8g2.firstPage();
  57. do {
  58.     u8g2.setCursor(0, 20);
  59.     u8g2.print(F("Please Wait.."));
  60.    } while ( u8g2.nextPage() );
  61. Serial.begin(9600);
  62. Serial.println("booting..");
  63. radio.begin();
  64. radio.openReadingPipe(0, address);
  65. radio.setPALevel(RF24_PA_LOW);
  66. radio.startListening();
  67. Serial.println("Booting Complete!");
  68. }
  69. //--------Main Loop--------
  70. void loop()
  71. {
  72.  
  73. TempCorrect = analogRead(A0);
  74. TempCorrect = map(TempCorrect, 0, 1023, 0, 10);
  75.  
  76. u8g2.setFont(u8g2_font_ncenB14_tr);
  77. u8g2.firstPage();
  78. radio.startListening();
  79. if ( radio.available()) {
  80.    while (radio.available()) {
  81.     FailCount = 0;
  82.      //--------Read the Signal---------
  83.     radio.read(&Hum, sizeof(Hum));
  84.     delay(600);
  85.     radio.read(&Light, sizeof(Light));
  86.     delay(600);
  87.     radio.read(&Temp, sizeof(Temp));
  88.     delay(600);
  89.    }
  90. }
  91. //----------------Correct Readings--------
  92. Serial.print(Hum);
  93. Serial.print("---");
  94. Serial.print(Light);
  95. Serial.print("---");
  96. Serial.println(Temp);
  97. TempC = Temp - TempCorrect;
  98.      
  99. L = Rain;
  100. L = constrain(L, LMin, LMax);
  101. L = map(L, LMin, LMax, 0, 100 );
  102.  
  103.   //------------ERROR COUNTER--------------
  104.   if(TempC > 40 || TempC < 0 || Light > 100 || Light < 0 || L > 100 || L < 0 ) {
  105.     WrongReadings++;
  106.     }
  107.    
  108.      
  109.   //------------Print the results!---------
  110.   if(Light > 0) {
  111.  
  112.  
  113.     do{
  114.     //--------Temp-------
  115.     u8g2.setCursor(0, 20);
  116.     u8g2.print(F("Temp"));
  117.     u8g2.setCursor(0, 40);
  118.     u8g2.print(TempC);
  119.     //--------Hum--------
  120.     u8g2.setCursor(80, 20);
  121.     u8g2.print(F("Hum"));
  122.     u8g2.setCursor(105, 40);    //horizontaal / verticaal ( in pixels )   Left upper corner: 0, 20
  123.     u8g2.print(Light);          //                                        Right upper corner: 80, 20
  124.     //---------Light-------     //                                        Left down corner: 0, 100
  125.     u8g2.setCursor(0, 100);     //                                        Right down corner:70, 100
  126.     u8g2.print(F("Light"));
  127.     u8g2.setCursor(0, 120);
  128.     u8g2.print(L);
  129.     u8g2.setCursor(35, 120);
  130.     u8g2.print(F("%"));
  131.        
  132.   } while ( u8g2.nextPage() );
  133.     }
  134.    
  135.   } //--------No Signal!--------
  136. /* else{
  137.    
  138.     FailCount = FailCount +1;
  139.     if(FailCount > MaxFails) {         //If it fails n times, print No Signal
  140.     Serial.println("No Signal");
  141.     do {
  142.     u8g2.setCursor(0, 20);
  143.     u8g2.print(F("No Signal!"));
  144.     u8g2.setCursor(0, 40);
  145.     u8g2.print(FailCount);
  146.      } while ( u8g2.nextPage() );
  147.    }
  148.   } */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top