Advertisement
Guest User

Untitled

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