Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //--------Comments--------
- //
- //
- //
- // Temp = TempC
- // Hum = Light
- // Light = L
- //
- //
- //------------------------
- //--------Libs--------
- #include <Arduino.h>
- #include <U8g2lib.h>
- #include <U8x8lib.h>
- #include <Arduino.h>
- #ifdef U8X8_HAVE_HW_SPI
- #include <SPI.h>
- #endif
- #include <nRF24L01.h>
- #include <RF24.h>
- //--------Objects--------
- RF24 radio(7 , 8); // CE, CSN
- U8G2_SSD1327_MIDAS_128X128_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
- //--------Integers-------
- const byte address[6] = "00001";
- int Temp;
- int Hum;
- int Light;
- int LightP;
- int Rain;
- int TempCorrect = 2; //Correction for the temperature overshoot of the DHT11, usually this is 2 degrees.
- //int Pot = A0;
- int TempC; // Corrected temp;
- int MaxFails = 6;
- int L;
- int LMin = 30;
- int LMax = 135;
- //bool Dev;
- int WrongReadings;
- int FailCount;
- //--------Startup--------
- void setup() {
- u8g2.begin();
- u8g2.setFont(u8g2_font_ncenB14_tr);
- u8g2.firstPage();
- do {
- u8g2.setCursor(0, 20);
- u8g2.print(F("Please Wait.."));
- } while ( u8g2.nextPage() );
- Serial.begin(9600);
- Serial.println("booting..");
- radio.begin();
- radio.openReadingPipe(0, address);
- radio.setPALevel(RF24_PA_LOW);
- radio.startListening();
- Serial.println("Booting Complete!");
- }
- //--------Main Loop--------
- void loop()
- {
- TempCorrect = analogRead(A0);
- TempCorrect = map(TempCorrect, 0, 1023, 0, 10);
- u8g2.setFont(u8g2_font_ncenB14_tr);
- u8g2.firstPage();
- radio.startListening();
- if ( radio.available()) {
- while (radio.available()) {
- FailCount = 0;
- //--------Read the Signal---------
- radio.read(&Hum, sizeof(Hum));
- delay(600);
- radio.read(&Light, sizeof(Light));
- delay(600);
- radio.read(&Temp, sizeof(Temp));
- delay(600);
- }
- }
- //----------------Correct Readings--------
- Serial.print(Hum);
- Serial.print("---");
- Serial.print(Light);
- Serial.print("---");
- Serial.println(Temp);
- TempC = Temp - TempCorrect;
- L = Rain;
- L = constrain(L, LMin, LMax);
- L = map(L, LMin, LMax, 0, 100 );
- //------------ERROR COUNTER--------------
- if(TempC > 40 || TempC < 0 || Light > 100 || Light < 0 || L > 100 || L < 0 ) {
- WrongReadings++;
- }
- //------------Print the results!---------
- if(Light > 0) {
- do{
- //--------Temp-------
- u8g2.setCursor(0, 20);
- u8g2.print(F("Temp"));
- u8g2.setCursor(0, 40);
- u8g2.print(TempC);
- //--------Hum--------
- u8g2.setCursor(80, 20);
- u8g2.print(F("Hum"));
- u8g2.setCursor(105, 40); //horizontaal / verticaal ( in pixels ) Left upper corner: 0, 20
- u8g2.print(Light); // Right upper corner: 80, 20
- //---------Light------- // Left down corner: 0, 100
- u8g2.setCursor(0, 100); // Right down corner:70, 100
- u8g2.print(F("Light"));
- u8g2.setCursor(0, 120);
- u8g2.print(L);
- u8g2.setCursor(35, 120);
- u8g2.print(F("%"));
- } while ( u8g2.nextPage() );
- }
- } //--------No Signal!--------
- /* else{
- FailCount = FailCount +1;
- if(FailCount > MaxFails) { //If it fails n times, print No Signal
- Serial.println("No Signal");
- do {
- u8g2.setCursor(0, 20);
- u8g2.print(F("No Signal!"));
- u8g2.setCursor(0, 40);
- u8g2.print(FailCount);
- } while ( u8g2.nextPage() );
- }
- } */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement