Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#include <TFT_HX8357.h> // Hardware-specific library
- #include <Wire.h>
- #include <SPI.h>
- //#include <Adafruit_Sensor.h>
- //#include <Adafruit_BME280.h>
- //#define BME_SCK 13
- //#define BME_MISO 12
- //#define BME_MOSI 11
- //#define BME_CS 9
- //Adafruit_BME280 bme(BME_CS); // hardware SPI
- #include <nRF24L01.h>
- #include <RF24.h>
- //#include <RF24_config.h>
- const byte thisSlaveAddress[5] = {'R','x','A','A','A'};
- RF24 radio(7, 8);
- //TFT_HX8357 tft = TFT_HX8357(); // Invoke custom library
- int Tips = 0;
- float Rain = 0;
- int Res = 0;
- int previousRemoteTemperature = 0;
- int previousRemoteHumidity = 0;
- int previousRemotePressure = 0;
- int previousRemoteTips = 0;
- int previousRemoteHours = 0;
- int previousRemoteMinutes = 0;
- int previousRemoteDay = 0;
- int previousRemoteMonth = 0;
- int previousRemoteYear = 0;
- int previousIndoorTemperature = 0;
- int previousIndoorHumidity = 0;
- int previousIndoorPressure = 0;
- int remoteTemperature = 0;
- int remoteHumidity = 0;
- int remotePressure = 0;
- int remoteTips = 0;
- int remoteHours = 0;
- int remoteMinutes = 0;
- int remoteDay = 0;
- int remoteMonth = 0;
- int remoteYear = 0;
- int indoorTemperature = 0;
- int indoorHumidity = 0;
- int indoorPressure = 0;
- struct package
- {
- int temperature;
- int pressure;
- int humidity;
- int tips;
- int rf_hh;
- int rf_mm;
- int rf_dd;
- int rf_mo;
- int rf_yy;
- };
- typedef struct package Package;
- Package data;
- void setup()
- {
- Serial.begin(115200);
- Serial.println(F("Start"));
- // Serial.println(F("BME280 test"));
- // bool status;
- // status = bme.begin();
- // if (!status) {
- // Serial.println("Could not find a valid BME280 sensor, check wiring!");
- // while (1);
- // }
- //Serial.println();
- // tft.init();
- // tft.setRotation(0);
- // tft.fillScreen(TFT_BLACK);
- // tft.setTextFont(1); // Select font 1 which is the Adafruit GLCD font
- // delay(100);
- startWirelessCommunication();
- // printUI();
- delay(1000);
- }
- void loop()
- {
- checkForWirelessData();
- // readSensor();
- // printIndoorTemperature();
- // printIndoorPressure();
- // printIndoorHumidity();
- // printRemoteTemperature();
- // printRemotePressure();
- // printRemoteHumidity();
- // printRemoteHours();
- // printRemoteMinutes();
- // printRemoteDay();
- // printRemoteMonth();
- // printRemoteYear();
- // printRemoteTips();
- }
- void startWirelessCommunication()
- {
- Serial.println(F("Start Wireless Comm"));
- radio.begin();
- radio.setDataRate( RF24_250KBPS ) ;
- radio.openReadingPipe(1, thisSlaveAddress);
- radio.startListening();
- delay(100);
- }
- void checkForWirelessData()
- {
- if ( radio.available())
- {
- while (radio.available())
- {
- radio.read( &data, sizeof(data) );
- remoteTemperature = data.temperature;
- remotePressure = data.pressure;
- remoteHumidity = data.humidity;
- remoteTips = data.tips;
- remoteHours = data.rf_hh;
- remoteMinutes = data.rf_mm;
- remoteDay = data.rf_dd;
- remoteMonth = data.rf_mo;
- remoteYear = data.rf_yy;
- }
- Serial.print("\nPackage:");
- Serial.print("\n");
- Serial.println(data.temperature);
- Serial.println(data.pressure);
- Serial.println(data.humidity);
- Serial.println(data.tips);
- Serial.println(data.rf_hh);
- Serial.println(data.rf_mm);
- Serial.println(data.rf_dd);
- Serial.println(data.rf_mo);
- Serial.println(data.rf_yy);
- }
- }
- //void readSensor()
- //{
- // previousIndoorTemperature = indoorTemperature;
- // previousIndoorPressure = indoorPressure;
- // previousIndoorHumidity = indoorHumidity;
- // indoorTemperature = bme.readTemperature();
- // indoorPressure = (bme.readPressure() / 100.0F);
- // indoorHumidity = bme.readHumidity();
- //}
- //void printIndoorTemperature()
- //{
- // if(indoorTemperature != previousIndoorTemperature)
- // {
- // tft.setCursor(155,145);
- // tft.setTextColor(TFT_CYAN);
- // tft.setTextSize(4);
- // tft.print(22);
- //tft.print(indoorTemperature);
- // previousIndoorTemperature = indoorTemperature;
- // }
- //}
- //void printIndoorPressure()
- //{
- // if(indoorPressure != previousIndoorPressure)
- // {
- // tft.setCursor(155,235);
- // tft.setTextColor(TFT_CYAN);
- // tft.setTextSize(4);
- // tft.print(50);
- // tft.print(indoorHumidity);
- // previousIndoorPressure = indoorPressure;
- // }
- //}
- //void printIndoorHumidity()
- //{
- // if(indoorHumidity != previousIndoorHumidity)
- // {
- // tft.setCursor(155,190);
- // tft.setTextColor(TFT_CYAN);
- // tft.setTextSize(4);
- // tft.print(90);
- // tft.print(indoorHumidity);
- // previousIndoorHumidity = indoorHumidity;
- // }
- //}
- //void printRemoteTemperature()
- //{
- // if (remoteTemperature != previousRemoteTemperature)
- // {
- // tft.setCursor(150, 344);
- // tft.setTextColor(TFT_GREEN);
- // tft.setTextSize(3);
- // tft.print(50);
- // tft.print(remoteTemperature);
- // Serial.print("Temp: ");
- // Serial.println(remoteTemperature);
- // previousRemoteTemperature = remoteTemperature;
- // }
- //}
- //void printRemotePressure()
- //{
- // if (remotePressure != previousRemotePressure)
- // {
- // tft.setCursor(150, 409);
- // tft.setTextColor(TFT_GREEN);
- // tft.setTextSize(3);
- // tft.print(55);
- // tft.print(remotePressure);
- // Serial.print("Pressure: ");
- // Serial.println(remotePressure);
- // previousRemotePressure = remotePressure;
- // }
- //}
- //void printRemoteHumidity()
- //{
- // if (remoteHumidity != previousRemoteHumidity)
- // {
- // tft.setCursor(150, 374);
- // tft.setTextColor(TFT_GREEN);
- // tft.setTextSize(3);
- // tft.print(10);
- // tft.print(remoteHumidity);
- // Serial.print("Humidity: ");
- // Serial.println(remoteHumidity);
- // previousRemoteHumidity = remoteHumidity;
- // }
- //}
- //void printRemoteHours()
- //{
- // if (remoteHours != previousRemoteHours)
- // {
- // tft.setCursor(224, 25);
- // tft.setTextColor(TFT_WHITE);
- // tft.setTextSize(3);
- // tft.print(14);
- // tft.print(remoteHours);
- // Serial.print("Hours: ");
- // Serial.println(remoteHours);
- // previousRemoteHours = remoteHours;
- // }
- //}
- //void printRemoteMinutes()
- //{
- // if (remoteMinutes != previousRemoteMinutes)
- // {
- // tft.setCursor(270, 25);
- // tft.setTextColor(TFT_WHITE);
- // tft.setTextSize(3);
- // tft.print(14);
- // tft.print(remoteMinutes);
- // Serial.print("Minutes: ");
- // Serial.println(remoteMinutes);
- // previousRemoteMinutes = remoteMinutes;
- // }
- //}
- //void printRemoteDay()
- //{
- // if (remoteDay != previousRemoteDay)
- // {
- // tft.setCursor(20, 25);
- // tft.setTextColor(TFT_WHITE);
- // tft.setTextSize(3);
- // tft.print(14);
- // tft.print(remoteDay);
- // Serial.print("Day: ");
- // Serial.println(remoteDay);
- // previousRemoteDay = remoteDay;
- // }
- //}
- //void printRemoteMonth()
- //{
- // if (remoteMonth != previousRemoteMonth)
- // {
- // tft.setCursor(77, 25);
- // tft.setTextColor(TFT_WHITE);
- // tft.setTextSize(3);
- // tft.print(14);
- // tft.print(remoteMonth);
- // Serial.print("Month: ");
- // Serial.println(remoteMonth);
- // previousRemoteMonth = remoteMonth;
- // }
- //}
- //void printRemoteYear()
- //{
- // if (remoteYear != previousRemoteYear)
- // {
- // tft.setCursor(134, 25);
- // tft.setTextColor(TFT_WHITE);
- // tft.setTextSize(3);
- // tft.print(2018);
- // tft.print(remoteYear);
- // Serial.print("Year: ");
- // Serial.println(remoteYear);
- // previousRemoteYear = remoteYear;
- // }
- //}
- //void printRemoteTips()
- //{
- //if (remoteTips == 0)
- //{
- // Serial.println("No Tips");
- //}
- // if (remoteTips != 0)
- // {
- // Tips = Tips + remoteTips;
- // Rain = Tips * 0.33
- // tft.setCursor(150, 439);
- // tft.setTextColor(TFT_GREEN);
- // tft.setTextSize(3);
- // tft.print(22);
- // tft.print(Tips);
- //Serial.print("Tips: ");
- //Serial.println(Tips);
- //if(remoteDay == 1 && remoteHours == 0 && remoteMinutes == 0 && Res == 0)
- //{
- //Rain = 0;
- //Res = 1;
- //}
- //if(remoteDay == 2)
- //{
- //Res = 0;
- //}
- //}
- // }
- //}
- //void printUI()
- //{
- // tft.drawRoundRect(5, 5, 310, 71, 5, TFT_WHITE);
- // tft.drawRoundRect(6, 6, 310, 71, 5, TFT_WHITE);
- // tft.drawRoundRect(5, 90, 310, 185, 5, TFT_WHITE);
- // tft.drawRoundRect(6, 91, 310, 185, 5, TFT_WHITE);
- // tft.drawRoundRect(5, 289, 310, 185, 5, TFT_WHITE);
- // tft.drawRoundRect(6, 290, 310, 185, 5, TFT_WHITE);
- // tft.fillRect(77, 90, 155, 40, TFT_CYAN);
- // tft.fillRect(77, 289, 155, 40, TFT_GREEN);
- // tft.setCursor(58, 25);
- // tft.setTextColor(TFT_WHITE);
- // tft.setTextSize(3);
- // tft.print("/");
- // tft.setCursor(115, 25);
- // tft.setTextColor(TFT_WHITE);
- // tft.setTextSize(3);
- // tft.print("-");
- // tft.setCursor(257, 25);
- // tft.setTextColor(TFT_WHITE);
- // tft.setTextSize(3);
- // tft.print(":");
- // tft.setCursor(115, 100);
- // tft.setTextColor(TFT_BLACK);
- // tft.setTextSize(3);
- // tft.print("INDE");
- // tft.setCursor(125, 299);
- // tft.setTextColor(TFT_BLACK);
- // tft.setTextSize(3);
- // tft.print("UDE");
- // tft.setCursor(230, 190);
- // tft.setTextColor(TFT_CYAN);
- // tft.setTextSize(4);
- // tft.print("%");
- // tft.setCursor(230, 374);
- // tft.setTextColor(TFT_GREEN);
- // tft.setTextSize(3);
- // tft.print("%");
- // tft.setCursor(230, 145);
- // tft.setTextColor(TFT_CYAN);
- // tft.setTextSize(2);
- // tft.print("o");
- // tft.setCursor(245, 145);
- // tft.setTextColor(TFT_CYAN);
- // tft.setTextSize(4);
- // tft.print("C");
- // tft.setCursor(230, 344);
- // tft.setTextColor(TFT_GREEN);
- // tft.setTextSize(1);
- // tft.print("o");
- // tft.setCursor(245, 344);
- // tft.setTextColor(TFT_GREEN);
- // tft.setTextSize(3);
- // tft.print("C");
- // tft.setCursor(230, 409);
- // tft.setTextColor(TFT_GREEN);
- // tft.setTextSize(3);
- // tft.print("hPa");
- // tft.setCursor(230, 439);
- // tft.setTextColor(TFT_GREEN);
- // tft.setTextSize(3);
- // tft.print("mm");
- // tft.setCursor(230, 235);
- // tft.setTextColor(TFT_CYAN);
- // tft.setTextSize(4);
- // tft.print("hPa");
- //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement