Advertisement
Guest User

Untitled

a guest
Aug 14th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.22 KB | None | 0 0
  1. //#include <TFT_HX8357.h> // Hardware-specific library
  2. #include <Wire.h>
  3. #include <SPI.h>
  4. //#include <Adafruit_Sensor.h>
  5. //#include <Adafruit_BME280.h>
  6. //#define BME_SCK 13
  7. //#define BME_MISO 12
  8. //#define BME_MOSI 11
  9. //#define BME_CS 9
  10.  
  11. //Adafruit_BME280 bme(BME_CS); // hardware SPI
  12.  
  13. #include <nRF24L01.h>
  14. #include <RF24.h>
  15. //#include <RF24_config.h>
  16. const byte thisSlaveAddress[5] = {'R','x','A','A','A'};
  17. RF24 radio(7, 8);
  18. //TFT_HX8357 tft = TFT_HX8357(); // Invoke custom library
  19.  
  20. int Tips = 0;
  21. float Rain = 0;
  22. int Res = 0;
  23.  
  24. int previousRemoteTemperature = 0;
  25. int previousRemoteHumidity = 0;
  26. int previousRemotePressure = 0;
  27. int previousRemoteTips = 0;
  28. int previousRemoteHours = 0;
  29. int previousRemoteMinutes = 0;
  30. int previousRemoteDay = 0;
  31. int previousRemoteMonth = 0;
  32. int previousRemoteYear = 0;
  33. int previousIndoorTemperature = 0;
  34. int previousIndoorHumidity = 0;
  35. int previousIndoorPressure = 0;
  36.  
  37. int remoteTemperature = 0;
  38. int remoteHumidity = 0;
  39. int remotePressure = 0;
  40. int remoteTips = 0;
  41. int remoteHours = 0;
  42. int remoteMinutes = 0;
  43. int remoteDay = 0;
  44. int remoteMonth = 0;
  45. int remoteYear = 0;
  46. int indoorTemperature = 0;
  47. int indoorHumidity = 0;
  48. int indoorPressure = 0;
  49.  
  50. struct package
  51. {
  52. int temperature;
  53. int pressure;
  54. int humidity;
  55. int tips;
  56. int rf_hh;
  57. int rf_mm;
  58. int rf_dd;
  59. int rf_mo;
  60. int rf_yy;
  61. };
  62.  
  63.  
  64.  
  65. typedef struct package Package;
  66. Package data;
  67.  
  68.  
  69. void setup()
  70. {
  71. Serial.begin(115200);
  72. Serial.println(F("Start"));
  73. // Serial.println(F("BME280 test"));
  74.  
  75. // bool status;
  76.  
  77.  
  78. // status = bme.begin();
  79. // if (!status) {
  80. // Serial.println("Could not find a valid BME280 sensor, check wiring!");
  81. // while (1);
  82. // }
  83.  
  84. //Serial.println();
  85.  
  86. // tft.init();
  87. // tft.setRotation(0);
  88. // tft.fillScreen(TFT_BLACK);
  89. // tft.setTextFont(1); // Select font 1 which is the Adafruit GLCD font
  90. // delay(100);
  91.  
  92. startWirelessCommunication();
  93.  
  94. // printUI();
  95.  
  96. delay(1000);
  97. }
  98.  
  99. void loop()
  100. {
  101.  
  102. checkForWirelessData();
  103. // readSensor();
  104. // printIndoorTemperature();
  105. // printIndoorPressure();
  106. // printIndoorHumidity();
  107. // printRemoteTemperature();
  108. // printRemotePressure();
  109. // printRemoteHumidity();
  110. // printRemoteHours();
  111. // printRemoteMinutes();
  112. // printRemoteDay();
  113. // printRemoteMonth();
  114. // printRemoteYear();
  115. // printRemoteTips();
  116. }
  117.  
  118. void startWirelessCommunication()
  119. {
  120. Serial.println(F("Start Wireless Comm"));
  121. radio.begin();
  122. radio.setDataRate( RF24_250KBPS ) ;
  123. radio.openReadingPipe(1, thisSlaveAddress);
  124. radio.startListening();
  125. delay(100);
  126. }
  127.  
  128. void checkForWirelessData()
  129. {
  130.  
  131. if ( radio.available())
  132. {
  133. while (radio.available())
  134. {
  135. radio.read( &data, sizeof(data) );
  136. remoteTemperature = data.temperature;
  137. remotePressure = data.pressure;
  138. remoteHumidity = data.humidity;
  139. remoteTips = data.tips;
  140. remoteHours = data.rf_hh;
  141. remoteMinutes = data.rf_mm;
  142. remoteDay = data.rf_dd;
  143. remoteMonth = data.rf_mo;
  144. remoteYear = data.rf_yy;
  145. }
  146. Serial.print("\nPackage:");
  147. Serial.print("\n");
  148. Serial.println(data.temperature);
  149. Serial.println(data.pressure);
  150. Serial.println(data.humidity);
  151. Serial.println(data.tips);
  152. Serial.println(data.rf_hh);
  153. Serial.println(data.rf_mm);
  154. Serial.println(data.rf_dd);
  155. Serial.println(data.rf_mo);
  156. Serial.println(data.rf_yy);
  157. }
  158. }
  159.  
  160. //void readSensor()
  161. //{
  162. // previousIndoorTemperature = indoorTemperature;
  163. // previousIndoorPressure = indoorPressure;
  164. // previousIndoorHumidity = indoorHumidity;
  165.  
  166. // indoorTemperature = bme.readTemperature();
  167. // indoorPressure = (bme.readPressure() / 100.0F);
  168. // indoorHumidity = bme.readHumidity();
  169. //}
  170.  
  171. //void printIndoorTemperature()
  172. //{
  173.  
  174. // if(indoorTemperature != previousIndoorTemperature)
  175. // {
  176.  
  177. // tft.setCursor(155,145);
  178. // tft.setTextColor(TFT_CYAN);
  179. // tft.setTextSize(4);
  180. // tft.print(22);
  181. //tft.print(indoorTemperature);
  182.  
  183. // previousIndoorTemperature = indoorTemperature;
  184.  
  185. // }
  186. //}
  187.  
  188. //void printIndoorPressure()
  189. //{
  190.  
  191. // if(indoorPressure != previousIndoorPressure)
  192. // {
  193.  
  194. // tft.setCursor(155,235);
  195. // tft.setTextColor(TFT_CYAN);
  196. // tft.setTextSize(4);
  197. // tft.print(50);
  198. // tft.print(indoorHumidity);
  199.  
  200. // previousIndoorPressure = indoorPressure;
  201.  
  202. // }
  203. //}
  204.  
  205. //void printIndoorHumidity()
  206. //{
  207. // if(indoorHumidity != previousIndoorHumidity)
  208. // {
  209.  
  210. // tft.setCursor(155,190);
  211. // tft.setTextColor(TFT_CYAN);
  212. // tft.setTextSize(4);
  213. // tft.print(90);
  214. // tft.print(indoorHumidity);
  215.  
  216. // previousIndoorHumidity = indoorHumidity;
  217.  
  218. // }
  219. //}
  220.  
  221. //void printRemoteTemperature()
  222. //{
  223.  
  224. // if (remoteTemperature != previousRemoteTemperature)
  225. // {
  226.  
  227. // tft.setCursor(150, 344);
  228. // tft.setTextColor(TFT_GREEN);
  229. // tft.setTextSize(3);
  230. // tft.print(50);
  231. // tft.print(remoteTemperature);
  232.  
  233. // Serial.print("Temp: ");
  234. // Serial.println(remoteTemperature);
  235.  
  236. // previousRemoteTemperature = remoteTemperature;
  237.  
  238. // }
  239. //}
  240.  
  241. //void printRemotePressure()
  242. //{
  243.  
  244. // if (remotePressure != previousRemotePressure)
  245. // {
  246.  
  247. // tft.setCursor(150, 409);
  248. // tft.setTextColor(TFT_GREEN);
  249. // tft.setTextSize(3);
  250. // tft.print(55);
  251. // tft.print(remotePressure);
  252.  
  253. // Serial.print("Pressure: ");
  254. // Serial.println(remotePressure);
  255.  
  256. // previousRemotePressure = remotePressure;
  257.  
  258. // }
  259. //}
  260.  
  261. //void printRemoteHumidity()
  262. //{
  263.  
  264. // if (remoteHumidity != previousRemoteHumidity)
  265. // {
  266.  
  267. // tft.setCursor(150, 374);
  268. // tft.setTextColor(TFT_GREEN);
  269. // tft.setTextSize(3);
  270. // tft.print(10);
  271. // tft.print(remoteHumidity);
  272.  
  273. // Serial.print("Humidity: ");
  274. // Serial.println(remoteHumidity);
  275.  
  276. // previousRemoteHumidity = remoteHumidity;
  277.  
  278. // }
  279. //}
  280.  
  281. //void printRemoteHours()
  282. //{
  283.  
  284. // if (remoteHours != previousRemoteHours)
  285. // {
  286.  
  287. // tft.setCursor(224, 25);
  288. // tft.setTextColor(TFT_WHITE);
  289. // tft.setTextSize(3);
  290. // tft.print(14);
  291. // tft.print(remoteHours);
  292.  
  293. // Serial.print("Hours: ");
  294. // Serial.println(remoteHours);
  295.  
  296. // previousRemoteHours = remoteHours;
  297.  
  298. // }
  299. //}
  300.  
  301. //void printRemoteMinutes()
  302. //{
  303.  
  304. // if (remoteMinutes != previousRemoteMinutes)
  305. // {
  306.  
  307. // tft.setCursor(270, 25);
  308. // tft.setTextColor(TFT_WHITE);
  309. // tft.setTextSize(3);
  310. // tft.print(14);
  311. // tft.print(remoteMinutes);
  312.  
  313. // Serial.print("Minutes: ");
  314. // Serial.println(remoteMinutes);
  315.  
  316. // previousRemoteMinutes = remoteMinutes;
  317.  
  318. // }
  319. //}
  320.  
  321. //void printRemoteDay()
  322. //{
  323.  
  324. // if (remoteDay != previousRemoteDay)
  325. // {
  326.  
  327. // tft.setCursor(20, 25);
  328. // tft.setTextColor(TFT_WHITE);
  329. // tft.setTextSize(3);
  330. // tft.print(14);
  331. // tft.print(remoteDay);
  332.  
  333. // Serial.print("Day: ");
  334. // Serial.println(remoteDay);
  335.  
  336. // previousRemoteDay = remoteDay;
  337.  
  338. // }
  339. //}
  340.  
  341. //void printRemoteMonth()
  342. //{
  343.  
  344. // if (remoteMonth != previousRemoteMonth)
  345. // {
  346.  
  347. // tft.setCursor(77, 25);
  348. // tft.setTextColor(TFT_WHITE);
  349. // tft.setTextSize(3);
  350. // tft.print(14);
  351. // tft.print(remoteMonth);
  352.  
  353. // Serial.print("Month: ");
  354. // Serial.println(remoteMonth);
  355.  
  356. // previousRemoteMonth = remoteMonth;
  357.  
  358. // }
  359. //}
  360.  
  361. //void printRemoteYear()
  362. //{
  363.  
  364. // if (remoteYear != previousRemoteYear)
  365. // {
  366.  
  367. // tft.setCursor(134, 25);
  368. // tft.setTextColor(TFT_WHITE);
  369. // tft.setTextSize(3);
  370. // tft.print(2018);
  371. // tft.print(remoteYear);
  372.  
  373. // Serial.print("Year: ");
  374. // Serial.println(remoteYear);
  375.  
  376. // previousRemoteYear = remoteYear;
  377.  
  378. // }
  379. //}
  380.  
  381. //void printRemoteTips()
  382. //{
  383.  
  384. //if (remoteTips == 0)
  385. //{
  386. // Serial.println("No Tips");
  387. //}
  388.  
  389. // if (remoteTips != 0)
  390. // {
  391.  
  392. // Tips = Tips + remoteTips;
  393. // Rain = Tips * 0.33
  394.  
  395.  
  396. // tft.setCursor(150, 439);
  397. // tft.setTextColor(TFT_GREEN);
  398. // tft.setTextSize(3);
  399. // tft.print(22);
  400. // tft.print(Tips);
  401.  
  402. //Serial.print("Tips: ");
  403. //Serial.println(Tips);
  404.  
  405.  
  406. //if(remoteDay == 1 && remoteHours == 0 && remoteMinutes == 0 && Res == 0)
  407. //{
  408.  
  409. //Rain = 0;
  410. //Res = 1;
  411.  
  412. //}
  413.  
  414. //if(remoteDay == 2)
  415. //{
  416.  
  417. //Res = 0;
  418.  
  419. //}
  420.  
  421.  
  422. //}
  423.  
  424.  
  425. // }
  426. //}
  427.  
  428. //void printUI()
  429. //{
  430.  
  431. // tft.drawRoundRect(5, 5, 310, 71, 5, TFT_WHITE);
  432. // tft.drawRoundRect(6, 6, 310, 71, 5, TFT_WHITE);
  433.  
  434. // tft.drawRoundRect(5, 90, 310, 185, 5, TFT_WHITE);
  435. // tft.drawRoundRect(6, 91, 310, 185, 5, TFT_WHITE);
  436.  
  437. // tft.drawRoundRect(5, 289, 310, 185, 5, TFT_WHITE);
  438. // tft.drawRoundRect(6, 290, 310, 185, 5, TFT_WHITE);
  439.  
  440. // tft.fillRect(77, 90, 155, 40, TFT_CYAN);
  441. // tft.fillRect(77, 289, 155, 40, TFT_GREEN);
  442.  
  443. // tft.setCursor(58, 25);
  444. // tft.setTextColor(TFT_WHITE);
  445. // tft.setTextSize(3);
  446. // tft.print("/");
  447.  
  448. // tft.setCursor(115, 25);
  449. // tft.setTextColor(TFT_WHITE);
  450. // tft.setTextSize(3);
  451. // tft.print("-");
  452.  
  453. // tft.setCursor(257, 25);
  454. // tft.setTextColor(TFT_WHITE);
  455. // tft.setTextSize(3);
  456. // tft.print(":");
  457.  
  458. // tft.setCursor(115, 100);
  459. // tft.setTextColor(TFT_BLACK);
  460. // tft.setTextSize(3);
  461. // tft.print("INDE");
  462.  
  463. // tft.setCursor(125, 299);
  464. // tft.setTextColor(TFT_BLACK);
  465. // tft.setTextSize(3);
  466. // tft.print("UDE");
  467.  
  468. // tft.setCursor(230, 190);
  469. // tft.setTextColor(TFT_CYAN);
  470. // tft.setTextSize(4);
  471. // tft.print("%");
  472.  
  473. // tft.setCursor(230, 374);
  474. // tft.setTextColor(TFT_GREEN);
  475. // tft.setTextSize(3);
  476. // tft.print("%");
  477.  
  478. // tft.setCursor(230, 145);
  479. // tft.setTextColor(TFT_CYAN);
  480. // tft.setTextSize(2);
  481. // tft.print("o");
  482.  
  483. // tft.setCursor(245, 145);
  484. // tft.setTextColor(TFT_CYAN);
  485. // tft.setTextSize(4);
  486. // tft.print("C");
  487.  
  488. // tft.setCursor(230, 344);
  489. // tft.setTextColor(TFT_GREEN);
  490. // tft.setTextSize(1);
  491. // tft.print("o");
  492.  
  493. // tft.setCursor(245, 344);
  494. // tft.setTextColor(TFT_GREEN);
  495. // tft.setTextSize(3);
  496. // tft.print("C");
  497.  
  498. // tft.setCursor(230, 409);
  499. // tft.setTextColor(TFT_GREEN);
  500. // tft.setTextSize(3);
  501. // tft.print("hPa");
  502.  
  503. // tft.setCursor(230, 439);
  504. // tft.setTextColor(TFT_GREEN);
  505. // tft.setTextSize(3);
  506. // tft.print("mm");
  507.  
  508. // tft.setCursor(230, 235);
  509. // tft.setTextColor(TFT_CYAN);
  510. // tft.setTextSize(4);
  511. // tft.print("hPa");
  512. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement