Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 48.64 KB | None | 0 0
  1.  
  2. String menuItems[] = {"Welcome!","Display Stats","Set Samsung", "Set Daewoo", "Add remote","Set Humidity(beta)",""};
  3. String subMenu[]={"17 C","18 C","19 C","20 C","21 C","22 C","23 C","24 C","25 C","Back",""};
  4. String subMenu1[]={"17 C","18 C","19 C","20 C","21 C","22 C","23 C","24 C","25 C","Back",""};
  5. String subMenuH[]={"30-40 %","40-50 %","35-45 %","<60%"};
  6.  
  7. #define maxLen 800
  8. #define rxPinIR 2
  9.  
  10. const int chipSelect = 53;
  11. volatile unsigned int irBuffer[maxLen]; //stores timings - volatile because changed by ISR
  12. volatile unsigned int x = 0; //Pointer thru irBuffer - volatile because changed by ISR
  13.  
  14. void rxIR_Interrupt_Handler() {
  15. if (x > maxLen) return; //ignore if irBuffer is already full
  16. irBuffer[x++] = micros(); //just continually record the time-stamp of signal transitions
  17.  
  18. }
  19. int readKey;
  20. int savedDistance = 0;
  21.  
  22. // Menu control variables
  23. int menuPage = 0;
  24. int maxMenuPages = 0;
  25. int cursorPosition = 0;
  26. int maxCursorPosition=0;
  27.  
  28. int subPage=0;
  29. int maxSubPages = 0;
  30. int subCursor=0;
  31. int maxCursorPositionS=0;
  32.  
  33. int subPageD=0;
  34. int maxSubPagesD = 0;
  35. int subCursorD=0;
  36. int maxCursorPositionD=0;
  37.  
  38. int subVar= -1;
  39.  
  40. int stats_var;
  41. int compare_stats;
  42.  
  43. byte downArrow[8] = {
  44. 0b00100, // *
  45. 0b00100, // *
  46. 0b00100, // *
  47. 0b00100, // *
  48. 0b00100, // *
  49. 0b10101, // * * *
  50. 0b01110, // ***
  51. 0b00100 // *
  52. };
  53.  
  54. byte upArrow[8] = {
  55. 0b00100, // *
  56. 0b01110, // ***
  57. 0b10101, // * * *
  58. 0b00100, // *
  59. 0b00100, // *
  60. 0b00100, // *
  61. 0b00100, // *
  62. 0b00100 // *
  63. };
  64.  
  65. byte menuCursor[8] = {
  66. B01000, // *
  67. B00100, // *
  68. B00010, // *
  69. B00001, // *
  70. B00010, // *
  71. B00100, // *
  72. B01000, // *
  73. B00000 //
  74. };
  75.  
  76.  
  77. #include <SPI.h>
  78. #include <SD.h>
  79. #include "DHT.h"
  80. #include <Wire.h>
  81. #include <LiquidCrystal.h>
  82. #include <IRremote.h>
  83. IRsend irsend;
  84.  
  85.  
  86. // Setting the LCD shields pins
  87. LiquidCrystal lcd(44, 46, 4, 5, 6, 7);
  88.  
  89. #define DHTPIN 8
  90. #define DHTTYPE DHT11
  91. DHT dht(DHTPIN, DHTTYPE);
  92.  
  93.  
  94. void setup() {
  95.  
  96. // Initializes serial communication
  97. Serial.begin(9600);
  98.  
  99. while(menuItems[maxCursorPosition]!=""){maxCursorPosition++;}
  100. maxCursorPosition--;
  101. maxMenuPages= maxCursorPosition;
  102. if(maxMenuPages>=1)maxMenuPages -= 1;
  103.  
  104. while(subMenu[maxCursorPositionS]!=""){maxCursorPositionS++;}
  105. maxCursorPositionS--;
  106. maxSubPages= maxCursorPositionS;
  107. if(maxSubPages>=1)maxSubPages -= 1;
  108.  
  109. while(subMenu1[maxCursorPositionD]!=""){maxCursorPositionD++;}
  110. maxCursorPositionD--;
  111. maxSubPagesD= maxCursorPositionD;
  112. if(maxSubPagesD>=1)maxSubPagesD -= 1;
  113.  
  114.  
  115.  
  116. // Initializes and clears the LCD screen
  117. lcd.begin(16, 2);
  118. lcd.clear();
  119.  
  120. dht.begin();
  121.  
  122. // Creates the byte for the 3 custom characters
  123. lcd.createChar(0, menuCursor);
  124. lcd.createChar(1, upArrow);
  125. lcd.createChar(2, downArrow);
  126.  
  127. attachInterrupt(digitalPinToInterrupt(rxPinIR), rxIR_Interrupt_Handler, CHANGE);//set up ISR for receiving IR signal
  128. }
  129.  
  130. void loop() {
  131. if(subVar == -1) {
  132. mainMenuDraw();
  133. drawCursor();
  134. operateMainMenu();
  135. } else if (subVar == 0){
  136. subMenuDraw();
  137. subCursorDraw();
  138. operateSub();
  139. }
  140. else if (subVar == 1){
  141. subMenuDrawD();
  142. subCursorDrawD();
  143. operateSubD();
  144. }
  145. }
  146. void mainMenuDraw() {
  147. Serial.print(menuPage);
  148. lcd.clear();
  149. lcd.setCursor(1, 0);
  150. lcd.print(menuItems[menuPage]);
  151. lcd.setCursor(1, 1);
  152. lcd.print(menuItems[menuPage + 1]);
  153. if (menuPage == 0) {
  154. lcd.setCursor(15, 1);
  155. lcd.write(byte(2));
  156. } else if (menuPage > 0 and menuPage < maxMenuPages) {
  157. lcd.setCursor(15, 1);
  158. lcd.write(byte(2));
  159. lcd.setCursor(15, 0);
  160. lcd.write(byte(1));
  161. } else if (menuPage == maxMenuPages) {
  162. lcd.setCursor(15, 0);
  163. lcd.write(byte(1));
  164. }
  165. }
  166.  
  167. void drawCursor() {
  168. for (int x = 0; x < 2; x++) { // Erases current cursor
  169. lcd.setCursor(0, x);
  170. lcd.print(" ");
  171. }
  172.  
  173. if (menuPage % 2 == 0) {
  174. if (cursorPosition % 2 == 0) { // If the menu page is even and the cursor position is even that means the cursor should be on line 1
  175. lcd.setCursor(0, 0);
  176. lcd.write(byte(0));
  177. }
  178. if (cursorPosition % 2 != 0) { // If the menu page is even and the cursor position is odd that means the cursor should be on line 2
  179. lcd.setCursor(0, 1);
  180. lcd.write(byte(0));
  181. }
  182. }
  183. if (menuPage % 2 != 0) {
  184. if (cursorPosition % 2 == 0) { // If the menu page is odd and the cursor position is even that means the cursor should be on line 2
  185. lcd.setCursor(0, 1);
  186. lcd.write(byte(0));
  187. }
  188. if (cursorPosition % 2 != 0) { // If the menu page is odd and the cursor position is odd that means the cursor should be on line 1
  189. lcd.setCursor(0, 0);
  190. lcd.write(byte(0));
  191. }
  192. }
  193. }
  194. void operateMainMenu() {
  195. int activeButton = 0;
  196. while (activeButton == 0) {
  197. int button;
  198. readKey = analogRead(0);
  199. if (readKey < 790) {
  200. delay(100);
  201. readKey = analogRead(0);
  202. }
  203. button = evaluateButton(readKey);
  204. switch (button) {
  205. case 0: // When button returns as 0 there is no action taken
  206. break;
  207. case 1: // This case will execute if the "forward" button is pressed
  208. button = 0;
  209. switch (cursorPosition) { // The case that is selected here is dependent on which menu page you are on and where the cursor is.
  210. case 0:
  211. break;
  212. case 1:
  213. menuItem1();
  214. break;
  215. case 2:
  216. subVar=0;
  217. break;
  218. case 3:
  219. subVar=1;
  220. //menuItem3();
  221. break;
  222. case 4:
  223. menuItem4();
  224. }
  225. activeButton = 1;
  226. mainMenuDraw();
  227. drawCursor();
  228. break;
  229. case 2:
  230. button = 0;
  231. if (menuPage == 0) {
  232. cursorPosition = cursorPosition - 1;
  233. cursorPosition = constrain(cursorPosition, 0, maxCursorPosition);
  234. }
  235. if (menuPage % 2 == 0 and cursorPosition % 2 == 0) {
  236. menuPage = menuPage - 1;
  237. menuPage = constrain(menuPage, 0, maxMenuPages);
  238. }
  239.  
  240. if (menuPage % 2 != 0 and cursorPosition % 2 != 0) {
  241. menuPage = menuPage - 1;
  242. menuPage = constrain(menuPage, 0, maxMenuPages);
  243. }
  244.  
  245. cursorPosition = cursorPosition - 1;
  246. cursorPosition = constrain(cursorPosition, 0, maxCursorPosition);
  247.  
  248. mainMenuDraw();
  249. drawCursor();
  250. activeButton = 1;
  251. break;
  252. case 3:
  253. button = 0;
  254. if (menuPage % 2 == 0 and cursorPosition % 2 != 0) {
  255. menuPage = menuPage + 1;
  256. menuPage = constrain(menuPage, 0, maxMenuPages);
  257. }
  258.  
  259. if (menuPage % 2 != 0 and cursorPosition % 2 == 0) {
  260. menuPage = menuPage + 1;
  261. menuPage = constrain(menuPage, 0, maxMenuPages);
  262. }
  263.  
  264. cursorPosition = cursorPosition + 1;
  265. cursorPosition = constrain(cursorPosition, 0, maxCursorPosition);
  266. activeButton = 1;
  267. mainMenuDraw();
  268. drawCursor();
  269. }}}
  270. int evaluateButton(int x) {
  271. int result = 0;
  272. if (x < 50) {
  273. result = 1; // right
  274. } else if (x < 195) {
  275. result = 2; // up
  276. } else if (x < 380) {
  277. result = 3; // down
  278. } else if (x < 790) {
  279. result = 4; // left
  280. }
  281. return result;
  282. }
  283. void drawInstructions() {
  284. lcd.setCursor(0, 1); // Set cursor to the bottom line
  285. lcd.print("Use ");
  286. lcd.write(byte(1)); // Up arrow
  287. lcd.print("/");
  288. lcd.write(byte(2)); // Down arrow
  289. lcd.print(" buttons");
  290. }
  291. void menuItem1() { // Function executes when you select the 3rd item from main menu
  292. int activeButton = 0;
  293. lcd.clear();
  294. lcd.begin(16, 2);
  295. dht.begin();
  296. lcd.print("Temp: Humidity:");
  297.  
  298. lcd.setCursor(0, 1);
  299. float h = dht.readHumidity();
  300. float f = dht.readTemperature(true);
  301.  
  302. if (isnan(h) || isnan(f)) {
  303. lcd.print("ERROR");
  304. return;
  305. }
  306. float f1;
  307. f1=(f-36)*5/9;
  308. lcd.print(round(f1));
  309. lcd.print(" C");
  310. lcd.setCursor(7,1);
  311. lcd.print(h);
  312. lcd.print("%");
  313.  
  314. while (activeButton == 0) {
  315. int button;
  316. readKey = analogRead(0);
  317. if (readKey < 790) {
  318. delay(100);
  319. readKey = analogRead(0);
  320. }
  321. button = evaluateButton(readKey);
  322. switch (button) {
  323. case 4: // This case will execute if the "back" button is pressed
  324. button = 0;
  325. activeButton = 1;
  326. break;
  327. }
  328. }
  329. }
  330. void menuItem4() { // Function executes when you select the 4th item from main menu
  331. int activeButton = 0;
  332. lcd.clear();
  333. lcd.setCursor(0, 0);
  334. lcd.print("Int SD...");
  335. if (!SD.begin(chipSelect)) {
  336. lcd.clear();
  337. lcd.print("Failed!");
  338. while (1);
  339. }
  340. delay(1000);
  341. lcd.clear();
  342. lcd.print("Card ok!");
  343. lcd.clear();
  344. delay(1000);
  345. lcd.print("Prepare...");
  346. delay(2000);
  347. lcd.clear();
  348. lcd.print("Press ON");
  349. Adding();
  350. delay(2000);
  351. lcd.clear();
  352. lcd.print("Press OFF");
  353. Adding();
  354. delay(2000);
  355. lcd.clear();
  356. lcd.print("Press Temp up");
  357. Adding();
  358. delay(2000);
  359. lcd.clear();
  360. lcd.print("Press Temp down");
  361. Adding();
  362. delay(2000);
  363. lcd.clear();
  364. lcd.print("Registered!");
  365.  
  366. while (activeButton == 0) {
  367. int button;
  368. readKey = analogRead(0);
  369. if (readKey < 790) {
  370. delay(100);
  371. readKey = analogRead(0);
  372. }
  373. button = evaluateButton(readKey);
  374. switch (button) {
  375. case 4: // This case will execute if the "back" button is pressed
  376. button = 0;
  377. activeButton = 1;
  378. break;
  379. }
  380. }
  381. }
  382. void Adding(){
  383. {
  384. // make a string for assembling the data to log:
  385. String dataString = "";
  386. delay(3000); // pause 5 secs
  387. if (x) { //if a signal is captured
  388. delay(3000);
  389. dataString += "Raw: ("; //dump raw header format - for library
  390. dataString += (x - 1);
  391. dataString += ") ";
  392. detachInterrupt(digitalPinToInterrupt(rxPinIR));//stop interrupts & capture until finshed here
  393. for (int i = 1; i < x; i++) { //now dump the times
  394. if (!(i & 0x1)) dataString += "";
  395. dataString += (irBuffer[i] - irBuffer[i - 1]);
  396. dataString += F(", ");
  397. }
  398. x = 0;
  399. attachInterrupt(digitalPinToInterrupt(rxPinIR), rxIR_Interrupt_Handler, CHANGE);//re-enable ISR for receiving IR signal
  400. }
  401. File dataFile = SD.open("Remotes.txt", FILE_WRITE);
  402.  
  403. // if the file is available, write to it:
  404. if (dataFile) {
  405. dataFile.println(dataString);
  406. dataFile.close();
  407. }
  408. delay(1000);
  409. lcd.clear();
  410. lcd.print("Added!");
  411. }
  412. }
  413. void sendSamsung_ON(){
  414. int khz = 38;
  415. unsigned int irSignal[] = {3016, 9016, 472, 576, 560, 1480, 532, 536, 484, 560, 560, 484, 536, 512, 556, 508, 536, 512, 524, 520, 560, 1504, 484, 560, 560, 484, 560, 1500, 520, 524, 564, 484, 556, 1504, 560, 1484, 488, 1568, 536, 1528, 520, 1516, 560, 512, 508, 536, 552, 544, 560, 484, 560, 484, 560, 508, 536, 512, 540, 504, 536, 508, 560, 512, 508, 536, 560, 536, 512, 532, 536, 508, 536, 536, 468, 576, 484, 560, 560, 484, 560, 508, 540, 504, 540, 508, 524, 520, 588, 488, 532, 536, 484, 560, 532, 512, 560, 508, 512, 532, 520, 528, 532, 512, 536, 508, 532, 536, 468, 1572, 560, 1500, 560, 1480, 536, 1524, 508, 1624, 2992, 9020, 516, 1524, 536, 508, 560, 508, 532, 508, 564, 488, 560, 484, 560, 508, 536, 508, 520, 524, 564, 1504, 464, 576, 532, 512, 564, 1500, 484, 560, 560, 484, 560, 488, 556, 1504, 560, 1500, 520, 1520, 560, 1556, 556, 1480, 560, 1504, 556, 1504, 540, 1500, 556, 1504, 560, 484, 560, 488, 556, 508, 536, 512, 512, 532, 560, 484, 560, 508, 536, 512, 508, 536, 560, 536, 560, 484, 564, 484, 556, 512, 484, 560, 560, 1500, 540, 1528, 556, 516, 460, 580, 548, 496, 560, 1504, 464, 580, 560, 484, 560, 508, 540, 504, 540, 500, 540, 512, 560, 488, 612, 1500, 560, 1480, 560, 1500, 560, 1500, 508};
  416. irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz); //Note the approach used to automatically calculate the size of the array.
  417. }
  418. void sendDaewoo_ON(){
  419. int khz = 38;
  420. unsigned int irSignal[] = {3128, 1596, 532, 1064, 532, 1064, 532, 216, 612, 216, 612, 216, 612, 1064, 532, 216, 612, 220, 608, 1064, 532, 1064, 532, 216, 584, 1088, 532, 220, 608, 220, 608, 1064, 532, 1064, 532, 220, 608, 1064, 532, 1064, 532, 216, 612, 216, 612, 1064, 528, 220, 612, 216, 612, 1064, 532, 216, 612, 216, 612, 216, 612, 220, 608, 216, 608, 224, 608, 220, 608, 220, 608, 220, 608, 220, 608, 216, 612, 220, 608, 220, 608, 220, 608, 220, 612, 216, 612, 216, 612, 1064, 528, 220, 608, 224, 604, 1064, 536, 216, 612, 216, 612, 1064, 532, 1060, 532, 220, 612, 216, 612, 216, 612, 216, 612, 216, 612, 216, 612, 220, 608, 220, 612, 212, 612, 1064, 532, 220, 612, 212, 612, 220, 612, 220, 608, 216, 612, 216, 612, 216, 612, 216, 612, 220, 608, 216, 612, 1064, 532, 220, 612, 216, 608, 220, 612, 212, 612, 220, 612, 216, 612, 216, 612, 216, 612, 216, 612, 216, 612, 216, 612, 216, 612, 216, 612, 216, 616, 212, 612, 216, 612, 220, 612, 212, 616, 212, 616, 212, 616, 212, 616, 216, 612, 216, 612, 216, 612, 216, 616, 212, 616, 212, 612, 216, 612, 220, 612, 212, 612, 216, 616, 212, 612, 1064, 536, 216, 612, 212, 616, 1060, 532, 216, 612, 220, 612, 208, 620, 212, 616, 212, 616};
  421. irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz); //Note the approach used to automatically calculate the size of the array.
  422. }
  423. void sendSamsung_OFF(){
  424. int khz = 38;
  425. unsigned int irSignal[] = {3044, 8996, 512, 532, 560, 1500, 540, 508, 540, 504, 560, 460, 584, 508, 540, 508, 512, 532, 560, 484, 560, 1500, 552, 496, 560, 484, 560, 1500, 592, 1500, 516, 528, 560, 1500, 488, 1548, 564, 1500, 564, 1528, 560, 1500, 560, 484, 560, 488, 560, 508, 536, 512, 560, 480, 588, 508, 564, 508, 564, 480, 588, 508, 564, 508, 560, 484, 588, 484, 588, 508, 560, 508, 564, 484, 588, 504, 564, 512, 560, 508, 492, 580, 512, 556, 524, 544, 540, 536, 536, 532, 540, 532, 568, 500, 576, 496, 580, 492, 584, 484, 588, 484, 592, 480, 588, 480, 592, 480, 588, 480, 592, 480, 588, 1500, 544, 1548, 460, 1288, 2996, 9016, 548, 1492, 560, 508, 536, 508, 516, 528, 564, 480, 564, 508, 536, 508, 512, 532, 560, 460, 588, 1500, 516, 528, 560, 484, 564, 508, 536, 508, 512, 528, 568, 1520, 568, 1500, 560, 1500, 516, 1524, 596, 1488, 564, 484, 564, 504, 540, 508, 540, 504, 564, 480, 564, 504, 540, 508, 560, 456, 616, 484, 588, 480, 588, 484, 588, 480, 592, 480, 588, 508, 564, 484, 584, 460, 612, 1500, 552, 1540, 560, 532, 540, 532, 536, 532, 540, 532, 512, 560, 540, 532, 536, 1496, 568, 480, 560, 1500, 564, 484, 560, 1524, 540, 532, 564, 508, 536, 536, 536, 532, 564, 508, 552, 516, 540, 536, 508, 1196, 2972, 9040, 560, 1552, 540, 532, 564, 512, 552, 512, 488, 584, 564, 508, 560, 512, 512, 556, 564, 508, 560, 1504, 488, 556, 560, 484, 560, 1500, 560, 1504, 560, 508, 560, 508, 568, 1496, 568, 1496, 472, 1564, 568, 1524, 564, 1496, 520, 1520, 560, 1500, 564, 1524, 560, 1480, 560, 508, 488, 556, 564, 480, 564, 484, 560, 512, 560, 484, 584, 512, 560, 512, 560, 508, 488, 580, 516, 556, 516, 552, 540, 504, 572, 532, 580, 1476, 564, 1500, 516, 528, 564, 508, 536, 484, 560, 1504, 564, 528, 544, 528, 572, 484, 588, 480, 596, 480, 596, 484, 592, 480, 588, 484, 588, 484, 584, 1476, 564, 1496, 512};
  426. irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz); //Note the approach used to automatically calculate the size of the array.
  427. }
  428. void sendDaewoo_OFF(){
  429. int khz = 38;
  430. unsigned int irSignal[] = {2392, 6188, 288, 7724, 288, 456, 344, 6852, 264, 2960, 252, 604, 296, 5464, 296, 26696, 288, 13032, 292, 6272, 264, 400, 288, 1456, 264, 8036, 292, 1240, 256, 9088, 264, 5148, 284, 2148, 268, 1428, 340, 62128, 3128, 1600, 528, 1064, 532, 1064, 532, 220, 608, 216, 612, 220, 608, 1064, 532, 220, 608, 224, 604, 1064, 532, 1064, 532, 220, 608, 1064, 528, 224, 604, 224, 608, 1064, 528, 1064, 532, 224, 604, 1064, 532, 1068, 528, 224, 604, 224, 604, 1068, 528, 224, 604, 224, 604, 1064, 532, 224, 608, 216, 612, 220, 604, 224, 604, 224, 608, 220, 608, 220, 608, 220, 608, 220, 608, 224, 604, 220, 608, 220, 608, 224, 604, 220, 608, 228, 604, 220, 608, 220, 604, 224, 608, 220, 608, 220, 608, 1064, 508, 272, 576, 228, 604, 1064, 532, 1064, 528, 224, 604, 224, 604, 224, 604, 224, 604, 228, 604, 224, 604, 1064, 532, 220, 608, 220, 608, 1064, 532, 220, 604, 228, 604, 220, 608, 224, 604, 224, 604, 224, 604, 224, 604, 224, 604, 224, 604, 224, 604, 1064, 532, 228, 600, 224, 604, 228, 604, 220, 608, 220, 604, 228, 604, 220, 608, 224, 604, 224, 604, 224, 604, 224, 604, 224, 604, 224, 604, 224, 608, 220, 604, 224, 604, 224, 604, 224, 608, 220, 608, 220, 608, 220, 608, 224, 600, 228, 604, 224, 604, 224, 604, 224, 604, 224, 608, 216, 608, 228, 604, 220, 608, 220, 608, 220, 608, 1064, 528, 1068, 532, 220, 608, 220, 608, 220, 608, 224, 604, 220, 608, 220, 584, 272, 580};
  431. irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz); //Note the approach used to automatically calculate the size of the array.
  432. }
  433.  
  434.  
  435. void subMenuDraw() {
  436. Serial.print(subPage);
  437. lcd.clear();
  438. lcd.setCursor(1, 0);
  439. lcd.print(subMenu[subPage]);
  440. lcd.setCursor(1, 1);
  441. lcd.print(subMenu[subPage + 1]);
  442. if (subPage == 0) {
  443. lcd.setCursor(15, 1);
  444. lcd.write(byte(2));
  445. } else if (subPage > 0 and subPage < maxSubPages) {
  446. lcd.setCursor(15, 1);
  447. lcd.write(byte(2));
  448. lcd.setCursor(15, 0);
  449. lcd.write(byte(1));
  450. } else if (subPage == maxSubPages) {
  451. lcd.setCursor(15, 0);
  452. lcd.write(byte(1));
  453. }
  454. }
  455.  
  456. void subCursorDraw() {
  457. for (int x = 0; x < 2; x++) { // Erases current cursor
  458. lcd.setCursor(0, x);
  459. lcd.print(" ");
  460. }
  461.  
  462. if (subPage % 2 == 0) {
  463. if (subCursor % 2 == 0) { // If the menu page is even and the cursor position is even that means the cursor should be on line 1
  464. lcd.setCursor(0, 0);
  465. lcd.write(byte(0));
  466. }
  467. if (subCursor % 2 != 0) { // If the menu page is even and the cursor position is odd that means the cursor should be on line 2
  468. lcd.setCursor(0, 1);
  469. lcd.write(byte(0));
  470. }
  471. }
  472. if (subPage % 2 != 0) {
  473. if (subCursor % 2 == 0) { // If the menu page is odd and the cursor position is even that means the cursor should be on line 2
  474. lcd.setCursor(0, 1);
  475. lcd.write(byte(0));
  476. }
  477. if (subCursor % 2 != 0) { // If the menu page is odd and the cursor position is odd that means the cursor should be on line 1
  478. lcd.setCursor(0, 0);
  479. lcd.write(byte(0));
  480. }
  481. }
  482. }
  483. void operateSub() {
  484. int activeButton = 0;
  485. while (activeButton == 0) {
  486. int button;
  487. readKey = analogRead(0);
  488. if (readKey < 790) {
  489. delay(100);
  490. readKey = analogRead(0);
  491. }
  492. button = evaluateButton(readKey);
  493. switch (button) {
  494. case 0: // When button returns as 0 there is no action taken
  495. break;
  496. case 1: // This case will execute if the "forward" button is pressed
  497. button = 0;
  498. switch (subCursor) { // The case that is selected here is dependent on which menu page you are on and where the cursor is.
  499. case 0:
  500. Temp17();
  501. break;
  502. case 1:
  503. Temp18();
  504. break;
  505. case 2:
  506. Temp19();
  507. break;
  508. case 3:
  509. Temp20();
  510. break;
  511. case 4:
  512. Temp21();
  513. break;
  514. case 5:
  515. Temp22();
  516. break;
  517. case 6:
  518. Temp23();
  519. break;
  520. case 7:
  521. Temp24();
  522. break;
  523. case 8:
  524. Temp25();
  525. break;
  526. case 9:
  527. subVar=-1;
  528. break;
  529. }
  530. activeButton = 1;
  531. subMenuDraw();
  532. subCursorDraw();
  533. break;
  534. case 2:
  535. button = 0;
  536. if (subPage == 0) {
  537. subCursor = subCursor - 1;
  538. subCursor = constrain(subCursor, 0, maxCursorPositionS);
  539. }
  540. if (subPage % 2 == 0 and subCursor % 2 == 0) {
  541. subPage = subPage - 1;
  542. subPage = constrain(subPage, 0, maxSubPages);}
  543.  
  544. if (subPage % 2 != 0 and subCursor % 2 != 0) {
  545. subPage = subPage - 1;
  546. subPage = constrain(subPage, 0, maxSubPages);
  547. }
  548.  
  549. subCursor = subCursor - 1;
  550. subCursor = constrain(subCursor, 0, maxCursorPositionS);
  551.  
  552. subMenuDraw();
  553. subCursorDraw();
  554. activeButton = 1;
  555. break;
  556. case 3:
  557. button = 0;
  558. if (subPage % 2 == 0 and subCursor % 2 != 0) {
  559. subPage = subPage + 1;
  560. subPage = constrain(subPage, 0, maxSubPages);
  561. }
  562.  
  563. if (subPage % 2 != 0 and subCursor % 2 == 0) {
  564. subPage = subPage + 1;
  565. subPage = constrain(subPage, 0, maxSubPages);
  566. }
  567.  
  568. subCursor = subCursor + 1;
  569. subCursor = constrain(subCursor, 0, maxCursorPositionS);
  570. activeButton = 1;
  571. subMenuDraw();
  572. subCursorDraw();
  573. }
  574. }
  575. }
  576. void Temp17() {
  577. int activeButton = 0;
  578.  
  579. lcd.clear();
  580. lcd.setCursor(0, 0);
  581. lcd.print("Temp 17 selected");
  582. delay(1000);
  583. lcd.clear();
  584. lcd.print("Scanning...");
  585. stats_var=17;
  586. compare_stats=Temperature_Scan();
  587. delay(1000);
  588. lcd.clear();
  589. if (stats_var == compare_stats){
  590. lcd.print("Temp is ok");
  591. lcd.clear();
  592. lcd.print("No action");}
  593. if (stats_var < compare_stats){
  594. lcd.print("Temp higher");
  595. delay(1000);
  596. lcd.clear();
  597. lcd.print("Turning AC on...");
  598. delay(1000);
  599. sendDaewoo_ON();
  600. lcd.clear();
  601. lcd.print("AC on!");
  602. lcd.setCursor(0,1);
  603. lcd.print("<-:Back");}
  604. if (stats_var > compare_stats){
  605. lcd.print("Temp lower");
  606. delay(1000);
  607. lcd.clear();
  608. lcd.print("Turning AC on...");
  609. delay(1000);
  610. sendSamsung_ON();
  611. lcd.clear();
  612. lcd.print("AC on!");
  613. lcd.setCursor(0,1);
  614. lcd.print("<-:Back");}
  615.  
  616. while (activeButton == 0) {
  617. int button;
  618. readKey = analogRead(0);
  619. if (readKey < 790) {
  620. delay(100);
  621. readKey = analogRead(0);
  622. }
  623. button = evaluateButton(readKey);
  624. switch (button) {
  625. case 4: // This case will execute if the "back" button is pressed
  626. button = 0;
  627. activeButton = 1;
  628. break;
  629. }
  630. }
  631. }
  632. void Temp18() {
  633. int activeButton = 0;
  634.  
  635. lcd.clear();
  636. lcd.setCursor(0, 0);
  637. lcd.print("Temp 18 selected");
  638. delay(1000);
  639. lcd.clear();
  640. lcd.print("Scanning...");
  641. stats_var=18;
  642. compare_stats=Temperature_Scan();
  643. delay(1000);
  644. lcd.clear();
  645. if (stats_var == compare_stats){
  646. lcd.print("Temp is ok");
  647. lcd.clear();
  648. lcd.print("No action");}
  649. if (stats_var < compare_stats){
  650. lcd.print("Temp higher");
  651. delay(1000);
  652. lcd.clear();
  653. lcd.print("Turning AC on...");
  654. delay(1000);
  655. sendSamsung_ON();
  656. lcd.clear();
  657. lcd.print("AC on!");
  658. lcd.setCursor(0,1);
  659. lcd.print("<-:Back");}
  660. if (stats_var > compare_stats){
  661. lcd.print("Temp lower");
  662. delay(1000);
  663. lcd.clear();
  664. lcd.print("Turning AC on...");
  665. delay(1000);
  666. sendSamsung_ON();
  667. lcd.clear();
  668. lcd.print("AC on!");
  669. lcd.setCursor(0,1);
  670. lcd.print("<-:Back");}
  671.  
  672. while (activeButton == 0) {
  673. int button;
  674. readKey = analogRead(0);
  675. if (readKey < 790) {
  676. delay(100);
  677. readKey = analogRead(0);
  678. }
  679. button = evaluateButton(readKey);
  680. switch (button) {
  681. case 4: // This case will execute if the "back" button is pressed
  682. button = 0;
  683. activeButton = 1;
  684. break;
  685. }
  686. }
  687. }
  688. void Temp19() {
  689. int activeButton = 0;
  690.  
  691. lcd.clear();
  692. lcd.setCursor(0, 0);
  693. lcd.print("Temp 19 selected");
  694. delay(1000);
  695. lcd.clear();
  696. lcd.print("Scanning...");
  697. stats_var=19;
  698. compare_stats=Temperature_Scan();
  699. delay(1000);
  700. lcd.clear();
  701. if (stats_var == compare_stats){
  702. lcd.print("Temp is ok");
  703. lcd.clear();
  704. lcd.print("No action");}
  705. if (stats_var < compare_stats){
  706. lcd.print("Temp higher");
  707. delay(1000);
  708. lcd.clear();
  709. lcd.print("Turning AC on...");
  710. delay(1000);
  711. sendSamsung_ON();;
  712. lcd.clear();
  713. lcd.print("AC on!");
  714. lcd.setCursor(0,1);
  715. lcd.print("<-:Back");}
  716. if (stats_var > compare_stats){
  717. lcd.print("Temp lower");
  718. delay(1000);
  719. lcd.clear();
  720. lcd.print("Turning AC on...");
  721. delay(1000);
  722. sendSamsung_ON();
  723. lcd.clear();
  724. lcd.print("AC on!");
  725. lcd.setCursor(0,1);
  726. lcd.print("<-:Back");}
  727.  
  728. while (activeButton == 0) {
  729. int button;
  730. readKey = analogRead(0);
  731. if (readKey < 790) {
  732. delay(100);
  733. readKey = analogRead(0);
  734. }
  735. button = evaluateButton(readKey);
  736. switch (button) {
  737. case 4: // This case will execute if the "back" button is pressed
  738. button = 0;
  739. activeButton = 1;
  740. break;
  741. }
  742. }
  743. }
  744. void Temp20() {
  745. int activeButton = 0;
  746.  
  747. lcd.clear();
  748. lcd.setCursor(0, 0);
  749. lcd.print("Temp 20 selected");
  750. delay(1000);
  751. lcd.clear();
  752. lcd.print("Scanning...");
  753. stats_var=20;
  754. compare_stats=Temperature_Scan();
  755. delay(1000);
  756. lcd.clear();
  757. if (stats_var == compare_stats){
  758. lcd.print("Temp is ok");
  759. lcd.clear();
  760. lcd.print("No action");}
  761. if (stats_var == compare_stats){
  762. lcd.print("Temp is ok");
  763. lcd.clear();
  764. lcd.print("No action req");}
  765. if (stats_var < compare_stats){
  766. lcd.print("Temp higher");
  767. delay(1000);
  768. lcd.clear();
  769. lcd.print("Turning AC on...");
  770. delay(1000);
  771. sendSamsung_ON();
  772. lcd.clear();
  773. lcd.print("AC on!");
  774. lcd.setCursor(0,1);
  775. lcd.print("<-:Back");}
  776. if (stats_var > compare_stats){
  777. lcd.print("Temp lower");
  778. delay(1000);
  779. lcd.clear();
  780. lcd.print("Turning AC on...");
  781. delay(1000);
  782. sendSamsung_ON();
  783. lcd.clear();
  784. lcd.print("AC on!");
  785. lcd.setCursor(0,1);
  786. lcd.print("<-:Back");}
  787.  
  788. while (activeButton == 0) {
  789. int button;
  790. readKey = analogRead(0);
  791. if (readKey < 790) {
  792. delay(100);
  793. readKey = analogRead(0);
  794. }
  795. button = evaluateButton(readKey);
  796. switch (button) {
  797. case 4: // This case will execute if the "back" button is pressed
  798. button = 0;
  799. activeButton = 1;
  800. break;
  801. }
  802. }
  803. }
  804. void Temp21() {
  805. int activeButton = 0;
  806.  
  807. lcd.clear();
  808. lcd.setCursor(0, 0);
  809. lcd.print("Temp 21 selected");
  810. delay(1000);
  811. lcd.clear();
  812. lcd.print("Scanning...");
  813. stats_var=21;
  814. compare_stats=Temperature_Scan();
  815. delay(1000);
  816. lcd.clear();
  817. if (stats_var == compare_stats){
  818. lcd.print("Temp is ok");
  819. lcd.clear();
  820. lcd.print("No action");}
  821. if (stats_var < compare_stats){
  822. lcd.print("Temp higher");
  823. delay(1000);
  824. lcd.clear();
  825. lcd.print("Turning AC on...");
  826. delay(1000);
  827. sendSamsung_ON();
  828. lcd.clear();
  829. lcd.print("AC on!");
  830. lcd.setCursor(0,1);
  831. lcd.print("<-:Back");}
  832. if (stats_var > compare_stats){
  833. lcd.print("Temp lower");
  834. delay(1000);
  835. lcd.clear();
  836. lcd.print("Turning AC on...");
  837. delay(1000);
  838. sendSamsung_ON();
  839. lcd.clear();
  840. lcd.print("AC on!");
  841. lcd.setCursor(0,1);
  842. lcd.print("<-:Back");}
  843.  
  844. while (activeButton == 0) {
  845. int button;
  846. readKey = analogRead(0);
  847. if (readKey < 790) {
  848. delay(100);
  849. readKey = analogRead(0);
  850. }
  851. button = evaluateButton(readKey);
  852. switch (button) {
  853. case 4: // This case will execute if the "back" button is pressed
  854. button = 0;
  855. activeButton = 1;
  856. break;
  857. }
  858. }
  859. }
  860. void Temp22() {
  861. int activeButton = 0;
  862.  
  863. lcd.clear();
  864. lcd.setCursor(0, 0);
  865. lcd.print("Temp 22 selected");
  866. delay(1000);
  867. lcd.clear();
  868. lcd.print("Scanning...");
  869. stats_var=22;
  870. compare_stats=Temperature_Scan();
  871. delay(1000);
  872. lcd.clear();
  873. if (stats_var == compare_stats){
  874. lcd.print("Temp is ok");
  875. lcd.clear();
  876. lcd.print("No action");}
  877. if (stats_var < compare_stats){
  878. lcd.print("Temp higher");
  879. delay(1000);
  880. lcd.clear();
  881. lcd.print("Turning AC on...");
  882. delay(1000);
  883. sendSamsung_ON();
  884. lcd.clear();
  885. lcd.print("AC on!");
  886. lcd.setCursor(0,1);
  887. lcd.print("<-:Back");}
  888. if (stats_var > compare_stats){
  889. lcd.print("Temp lower");
  890. delay(1000);
  891. lcd.clear();
  892. lcd.print("Turning AC on...");
  893. delay(1000);
  894. sendSamsung_ON();
  895. lcd.clear();
  896. lcd.print("AC on!");
  897. lcd.setCursor(0,1);
  898. lcd.print("<-:Back");}
  899.  
  900. while (activeButton == 0) {
  901. int button;
  902. readKey = analogRead(0);
  903. if (readKey < 790) {
  904. delay(100);
  905. readKey = analogRead(0);
  906. }
  907. button = evaluateButton(readKey);
  908. switch (button) {
  909. case 4: // This case will execute if the "back" button is pressed
  910. button = 0;
  911. activeButton = 1;
  912. break;
  913. }
  914. }
  915. }
  916. void Temp23() {
  917. int activeButton = 0;
  918.  
  919. lcd.clear();
  920. lcd.setCursor(0, 0);
  921. lcd.print("Temp 23 selected");
  922. delay(1000);
  923. lcd.clear();
  924. lcd.print("Scanning...");
  925. stats_var=23;
  926. compare_stats=Temperature_Scan();
  927. delay(1000);
  928. lcd.clear();
  929. if (stats_var == compare_stats){
  930. lcd.print("Temp is ok");
  931. lcd.clear();
  932. lcd.print("No action");}
  933. if (stats_var < compare_stats){
  934. lcd.print("Temp higher");
  935. delay(1000);
  936. lcd.clear();
  937. lcd.print("Turning AC on...");
  938. delay(1000);
  939. sendSamsung_ON();
  940. lcd.clear();
  941. lcd.print("AC on!");
  942. lcd.setCursor(0,1);
  943. lcd.print("<-:Back");}
  944. if (stats_var > compare_stats){
  945. lcd.print("Temp lower");
  946. delay(1000);
  947. lcd.clear();
  948. lcd.print("Turning AC on...");
  949. delay(1000);
  950. sendSamsung_ON();
  951. lcd.clear();
  952. lcd.print("AC on!");
  953. lcd.setCursor(0,1);
  954. lcd.print("<-:Back");}
  955.  
  956. while (activeButton == 0) {
  957. int button;
  958. readKey = analogRead(0);
  959. if (readKey < 790) {
  960. delay(100);
  961. readKey = analogRead(0);
  962. }
  963. button = evaluateButton(readKey);
  964. switch (button) {
  965. case 4: // This case will execute if the "back" button is pressed
  966. button = 0;
  967. activeButton = 1;
  968. break;
  969. }
  970. }
  971. }
  972. void Temp24() {
  973. int activeButton = 0;
  974.  
  975. lcd.clear();
  976. lcd.setCursor(0, 0);
  977. lcd.print("Temp 24 selected");
  978. delay(1000);
  979. lcd.clear();
  980. lcd.print("Scanning...");
  981. stats_var=24;
  982. compare_stats=Temperature_Scan();
  983. delay(1000);
  984. lcd.clear();
  985. if (stats_var == compare_stats){
  986. lcd.print("Temp is ok");
  987. lcd.clear();
  988. lcd.print("No action");}
  989. if (stats_var < compare_stats){
  990. lcd.print("Temp higher");
  991. delay(1000);
  992. lcd.clear();
  993. lcd.print("Turning AC on...");
  994. delay(1000);
  995. sendSamsung_ON();
  996. lcd.clear();
  997. lcd.print("AC on!");
  998. lcd.setCursor(0,1);
  999. lcd.print("<-:Back");}
  1000. if (stats_var > compare_stats){
  1001. lcd.print("Temp lower");
  1002. delay(1000);
  1003. lcd.clear();
  1004. lcd.print("Turning AC on...");
  1005. delay(1000);
  1006. sendSamsung_ON();
  1007. lcd.clear();
  1008. lcd.print("AC on!");
  1009. lcd.setCursor(0,1);
  1010. lcd.print("<-:Back");}
  1011.  
  1012. while (activeButton == 0) {
  1013. int button;
  1014. readKey = analogRead(0);
  1015. if (readKey < 790) {
  1016. delay(100);
  1017. readKey = analogRead(0);
  1018. }
  1019. button = evaluateButton(readKey);
  1020. switch (button) {
  1021. case 4: // This case will execute if the "back" button is pressed
  1022. button = 0;
  1023. activeButton = 1;
  1024. break;
  1025. }
  1026. }
  1027. }
  1028. void Temp25() {
  1029. int activeButton = 0;
  1030.  
  1031. lcd.clear();
  1032. lcd.setCursor(0, 0);
  1033. lcd.print("Temp 25 selected");
  1034. delay(1000);
  1035. lcd.clear();
  1036. lcd.print("Scanning...");
  1037. stats_var=24;
  1038. compare_stats=Temperature_Scan();
  1039. delay(1000);
  1040. lcd.clear();
  1041. if (stats_var == compare_stats){
  1042. lcd.print("Temp is ok");
  1043. lcd.clear();
  1044. lcd.print("No action");}
  1045. if (stats_var < compare_stats){
  1046. lcd.print("Temp higher");
  1047. delay(1000);
  1048. lcd.clear();
  1049. lcd.print("Turning AC on...");
  1050. delay(1000);
  1051. sendSamsung_ON();
  1052. lcd.clear();
  1053. lcd.print("AC on!");
  1054. lcd.setCursor(0,1);
  1055. lcd.print("<-:Back");}
  1056. if (stats_var > compare_stats){
  1057. lcd.print("Temp lower");
  1058. delay(1000);
  1059. lcd.clear();
  1060. lcd.print("Turning AC on...");
  1061. delay(1000);
  1062. sendSamsung_ON();
  1063. lcd.clear();
  1064. lcd.print("AC on!");
  1065. lcd.setCursor(0,1);
  1066. lcd.print("<-:Back");}
  1067.  
  1068. while (activeButton == 0) {
  1069. int button;
  1070. readKey = analogRead(0);
  1071. if (readKey < 790) {
  1072. delay(100);
  1073. readKey = analogRead(0);
  1074. }
  1075. button = evaluateButton(readKey);
  1076. switch (button) {
  1077. case 4: // This case will execute if the "back" button is pressed
  1078. button = 0;
  1079. activeButton = 1;
  1080. break;
  1081. }
  1082. }
  1083. }
  1084.  
  1085. void subMenuDrawD() {
  1086. Serial.print(subPageD);
  1087. lcd.clear();
  1088. lcd.setCursor(1, 0);
  1089. lcd.print(subMenu1[subPageD]);
  1090. lcd.setCursor(1, 1);
  1091. lcd.print(subMenu1[subPageD + 1]);
  1092. if (subPageD == 0) {
  1093. lcd.setCursor(15, 1);
  1094. lcd.write(byte(2));
  1095. } else if (subPageD > 0 and subPageD < maxSubPagesD) {
  1096. lcd.setCursor(15, 1);
  1097. lcd.write(byte(2));
  1098. lcd.setCursor(15, 0);
  1099. lcd.write(byte(1));
  1100. } else if (subPageD == maxSubPagesD) {
  1101. lcd.setCursor(15, 0);
  1102. lcd.write(byte(1));
  1103. }
  1104. }
  1105.  
  1106. void subCursorDrawD() {
  1107. for (int x = 0; x < 2; x++) { // Erases current cursor
  1108. lcd.setCursor(0, x);
  1109. lcd.print(" ");
  1110. }
  1111.  
  1112. if (subPageD % 2 == 0) {
  1113. if (subCursorD % 2 == 0) { // If the menu page is even and the cursor position is even that means the cursor should be on line 1
  1114. lcd.setCursor(0, 0);
  1115. lcd.write(byte(0));
  1116. }
  1117. if (subCursorD % 2 != 0) { // If the menu page is even and the cursor position is odd that means the cursor should be on line 2
  1118. lcd.setCursor(0, 1);
  1119. lcd.write(byte(0));
  1120. }
  1121. }
  1122. if (subPageD % 2 != 0) {
  1123. if (subCursorD % 2 == 0) { // If the menu page is odd and the cursor position is even that means the cursor should be on line 2
  1124. lcd.setCursor(0, 1);
  1125. lcd.write(byte(0));
  1126. }
  1127. if (subCursorD % 2 != 0) { // If the menu page is odd and the cursor position is odd that means the cursor should be on line 1
  1128. lcd.setCursor(0, 0);
  1129. lcd.write(byte(0));
  1130. }
  1131. }
  1132. }
  1133. void operateSubD() {
  1134. int activeButton = 0;
  1135. while (activeButton == 0) {
  1136. int button;
  1137. readKey = analogRead(0);
  1138. if (readKey < 790) {
  1139. delay(100);
  1140. readKey = analogRead(0);
  1141. }
  1142. button = evaluateButton(readKey);
  1143. switch (button) {
  1144. case 0: // When button returns as 0 there is no action taken
  1145. break;
  1146. case 1: // This case will execute if the "forward" button is pressed
  1147. button = 0;
  1148. switch (subCursorD) { // The case that is selected here is dependent on which menu page you are on and where the cursor is.
  1149. case 0:
  1150. TempD17();
  1151. break;
  1152. case 1:
  1153. TempD18();
  1154. break;
  1155. case 2:
  1156. TempD19();
  1157. break;
  1158. case 3:
  1159. TempD20();
  1160. break;
  1161. case 4:
  1162. TempD21();
  1163. break;
  1164. case 5:
  1165. TempD22();
  1166. break;
  1167. case 6:
  1168. TempD23();
  1169. break;
  1170. case 7:
  1171. TempD24();
  1172. break;
  1173. case 8:
  1174. TempD25();
  1175. break;
  1176. case 9:
  1177. subVar=-1;
  1178. break;
  1179. }
  1180. activeButton = 1;
  1181. subMenuDrawD();
  1182. subCursorDrawD();
  1183. break;
  1184. case 2:
  1185. button = 0;
  1186. if (subPageD == 0) {
  1187. subCursorD = subCursorD - 1;
  1188. subCursorD = constrain(subCursorD, 0, maxCursorPositionD);
  1189. }
  1190. if (subPageD % 2 == 0 and subCursorD % 2 == 0) {
  1191. subPageD = subPageD - 1;
  1192. subPageD = constrain(subPageD, 0, maxSubPagesD);}
  1193.  
  1194. if (subPageD % 2 != 0 and subCursorD % 2 != 0) {
  1195. subPageD = subPageD - 1;
  1196. subPageD = constrain(subPageD, 0, maxSubPagesD);
  1197. }
  1198.  
  1199. subCursorD = subCursorD - 1;
  1200. subCursorD = constrain(subCursorD, 0, maxCursorPositionD);
  1201.  
  1202. subMenuDraw();
  1203. subCursorDraw();
  1204. activeButton = 1;
  1205. break;
  1206. case 3:
  1207. button = 0;
  1208. if (subPageD % 2 == 0 and subCursorD % 2 != 0) {
  1209. subPageD = subPageD + 1;
  1210. subPageD = constrain(subPageD, 0, maxSubPagesD);
  1211. }
  1212.  
  1213. if (subPageD % 2 != 0 and subCursorD % 2 == 0) {
  1214. subPageD = subPageD + 1;
  1215. subPageD = constrain(subPageD, 0, maxSubPagesD);
  1216. }
  1217.  
  1218. subCursorD = subCursorD + 1;
  1219. subCursorD = constrain(subCursorD, 0, maxCursorPositionD);
  1220. activeButton = 1;
  1221. subMenuDrawD();
  1222. subCursorDrawD();
  1223. }
  1224. }
  1225. }
  1226. void TempD17() {
  1227. int activeButton = 0;
  1228.  
  1229. lcd.clear();
  1230. lcd.setCursor(0, 0);
  1231. lcd.print("Temp 17 selected");
  1232. delay(1000);
  1233. lcd.clear();
  1234. lcd.print("Scanning...");
  1235. stats_var=17;
  1236. compare_stats=Temperature_Scan();
  1237. delay(1000);
  1238. lcd.clear();
  1239. if (stats_var == compare_stats){
  1240. lcd.print("Temp is ok");
  1241. lcd.clear();
  1242. lcd.print("No action");}
  1243. if (stats_var < compare_stats){
  1244. lcd.print("Temp higher");
  1245. delay(1000);
  1246. lcd.clear();
  1247. lcd.print("Turning AC on...");
  1248. delay(1000);
  1249. sendDaewoo_ON();
  1250. lcd.clear();
  1251. lcd.print("AC on!");
  1252. lcd.setCursor(0,1);
  1253. lcd.print("<-:Back");}
  1254. if (stats_var > compare_stats){
  1255. lcd.print("Temp lower");
  1256. delay(1000);
  1257. lcd.clear();
  1258. lcd.print("Turning AC on...");
  1259. delay(1000);
  1260. sendDaewoo_ON();
  1261. lcd.clear();
  1262. lcd.print("AC on!");
  1263. lcd.setCursor(0,1);
  1264. lcd.print("<-:Back");}
  1265.  
  1266. while (activeButton == 0) {
  1267. int button;
  1268. readKey = analogRead(0);
  1269. if (readKey < 790) {
  1270. delay(100);
  1271. readKey = analogRead(0);
  1272. }
  1273. button = evaluateButton(readKey);
  1274. switch (button) {
  1275. case 4: // This case will execute if the "back" button is pressed
  1276. button = 0;
  1277. activeButton = 1;
  1278. break;
  1279. }
  1280. }
  1281. }
  1282. void TempD18() {
  1283. int activeButton = 0;
  1284.  
  1285. lcd.clear();
  1286. lcd.setCursor(0, 0);
  1287. lcd.print("Temp 18 selected");
  1288. delay(1000);
  1289. lcd.clear();
  1290. lcd.print("Scanning...");
  1291. stats_var=18;
  1292. compare_stats=Temperature_Scan();
  1293. delay(1000);
  1294. lcd.clear();
  1295. if (stats_var == compare_stats){
  1296. lcd.print("Temp is ok");
  1297. lcd.clear();
  1298. lcd.print("No action");}
  1299. if (stats_var < compare_stats){
  1300. lcd.print("Temp higher");
  1301. delay(1000);
  1302. lcd.clear();
  1303. lcd.print("Turning AC on...");
  1304. delay(1000);
  1305. sendDaewoo_ON();
  1306. lcd.clear();
  1307. lcd.print("AC on!");
  1308. lcd.setCursor(0,1);
  1309. lcd.print("<-:Back");}
  1310. if (stats_var > compare_stats){
  1311. lcd.print("Temp lower");
  1312. delay(1000);
  1313. lcd.clear();
  1314. lcd.print("Turning AC on...");
  1315. delay(1000);
  1316. sendDaewoo_ON();
  1317. lcd.clear();
  1318. lcd.print("AC on!");
  1319. lcd.setCursor(0,1);
  1320. lcd.print("<-:Back");}
  1321.  
  1322. while (activeButton == 0) {
  1323. int button;
  1324. readKey = analogRead(0);
  1325. if (readKey < 790) {
  1326. delay(100);
  1327. readKey = analogRead(0);
  1328. }
  1329. button = evaluateButton(readKey);
  1330. switch (button) {
  1331. case 4: // This case will execute if the "back" button is pressed
  1332. button = 0;
  1333. activeButton = 1;
  1334. break;
  1335. }
  1336. }
  1337. }
  1338. void TempD19() {
  1339. int activeButton = 0;
  1340.  
  1341. lcd.clear();
  1342. lcd.setCursor(0, 0);
  1343. lcd.print("Temp 19 selected");
  1344. delay(1000);
  1345. lcd.clear();
  1346. lcd.print("Scanning...");
  1347. stats_var=19;
  1348. compare_stats=Temperature_Scan();
  1349. delay(1000);
  1350. lcd.clear();
  1351. if (stats_var == compare_stats){
  1352. lcd.print("Temp is ok");
  1353. lcd.clear();
  1354. lcd.print("No action");}
  1355. if (stats_var < compare_stats){
  1356. lcd.print("Temp higher");
  1357. delay(1000);
  1358. lcd.clear();
  1359. lcd.print("Turning AC on...");
  1360. delay(1000);
  1361. sendDaewoo_ON();
  1362. lcd.clear();
  1363. lcd.print("AC on!");
  1364. lcd.setCursor(0,1);
  1365. lcd.print("<-:Back");}
  1366. if (stats_var > compare_stats){
  1367. lcd.print("Temp lower");
  1368. delay(1000);
  1369. lcd.clear();
  1370. lcd.print("Turning AC on...");
  1371. delay(1000);
  1372. sendDaewoo_ON();
  1373. lcd.clear();
  1374. lcd.print("AC on!");
  1375. lcd.setCursor(0,1);
  1376. lcd.print("<-:Back");}
  1377.  
  1378. while (activeButton == 0) {
  1379. int button;
  1380. readKey = analogRead(0);
  1381. if (readKey < 790) {
  1382. delay(100);
  1383. readKey = analogRead(0);
  1384. }
  1385. button = evaluateButton(readKey);
  1386. switch (button) {
  1387. case 4: // This case will execute if the "back" button is pressed
  1388. button = 0;
  1389. activeButton = 1;
  1390. break;
  1391. }
  1392. }
  1393. }
  1394. void TempD20() {
  1395. int activeButton = 0;
  1396.  
  1397. lcd.clear();
  1398. lcd.setCursor(0, 0);
  1399. lcd.print("Temp 20 selected");
  1400. delay(1000);
  1401. lcd.clear();
  1402. lcd.print("Scanning...");
  1403. stats_var=20;
  1404. compare_stats=Temperature_Scan();
  1405. delay(1000);
  1406. lcd.clear();
  1407. if (stats_var == compare_stats){
  1408. lcd.print("Temp is ok");
  1409. lcd.clear();
  1410. lcd.print("No action");}
  1411. if (stats_var == compare_stats){
  1412. lcd.print("Temp is ok");
  1413. lcd.clear();
  1414. lcd.print("No action req");}
  1415. if (stats_var < compare_stats){
  1416. lcd.print("Temp higher");
  1417. delay(1000);
  1418. lcd.clear();
  1419. lcd.print("Turning AC on...");
  1420. delay(1000);
  1421. sendDaewoo_ON();
  1422. lcd.clear();
  1423. lcd.print("AC on!");
  1424. lcd.setCursor(0,1);
  1425. lcd.print("<-:Back");}
  1426. if (stats_var > compare_stats){
  1427. lcd.print("Temp lower");
  1428. delay(1000);
  1429. lcd.clear();
  1430. lcd.print("Turning AC on...");
  1431. delay(1000);
  1432. sendDaewoo_ON();
  1433. lcd.clear();
  1434. lcd.print("AC on!");
  1435. lcd.setCursor(0,1);
  1436. lcd.print("<-:Back");}
  1437.  
  1438. while (activeButton == 0) {
  1439. int button;
  1440. readKey = analogRead(0);
  1441. if (readKey < 790) {
  1442. delay(100);
  1443. readKey = analogRead(0);
  1444. }
  1445. button = evaluateButton(readKey);
  1446. switch (button) {
  1447. case 4: // This case will execute if the "back" button is pressed
  1448. button = 0;
  1449. activeButton = 1;
  1450. break;
  1451. }
  1452. }
  1453. }
  1454. void TempD21() {
  1455. int activeButton = 0;
  1456.  
  1457. lcd.clear();
  1458. lcd.setCursor(0, 0);
  1459. lcd.print("Temp 21 selected");
  1460. delay(1000);
  1461. lcd.clear();
  1462. lcd.print("Scanning...");
  1463. stats_var=21;
  1464. compare_stats=Temperature_Scan();
  1465. delay(1000);
  1466. lcd.clear();
  1467. if (stats_var == compare_stats){
  1468. lcd.print("Temp is ok");
  1469. lcd.clear();
  1470. lcd.print("No action");}
  1471. if (stats_var < compare_stats){
  1472. lcd.print("Temp higher");
  1473. delay(1000);
  1474. lcd.clear();
  1475. lcd.print("Turning AC on...");
  1476. delay(1000);
  1477. sendDaewoo_ON();
  1478. lcd.clear();
  1479. lcd.print("AC on!");
  1480. lcd.setCursor(0,1);
  1481. lcd.print("<-:Back");}
  1482. if (stats_var > compare_stats){
  1483. lcd.print("Temp lower");
  1484. delay(1000);
  1485. lcd.clear();
  1486. lcd.print("Turning AC on...");
  1487. delay(1000);
  1488. sendDaewoo_ON();
  1489. lcd.clear();
  1490. lcd.print("AC on!");
  1491. lcd.setCursor(0,1);
  1492. lcd.print("<-:Back");}
  1493.  
  1494. while (activeButton == 0) {
  1495. int button;
  1496. readKey = analogRead(0);
  1497. if (readKey < 790) {
  1498. delay(100);
  1499. readKey = analogRead(0);
  1500. }
  1501. button = evaluateButton(readKey);
  1502. switch (button) {
  1503. case 4: // This case will execute if the "back" button is pressed
  1504. button = 0;
  1505. activeButton = 1;
  1506. break;
  1507. }
  1508. }
  1509. }
  1510. void TempD22() {
  1511. int activeButton = 0;
  1512.  
  1513. lcd.clear();
  1514. lcd.setCursor(0, 0);
  1515. lcd.print("Temp 22 selected");
  1516. delay(1000);
  1517. lcd.clear();
  1518. lcd.print("Scanning...");
  1519. stats_var=22;
  1520. compare_stats=Temperature_Scan();
  1521. delay(1000);
  1522. lcd.clear();
  1523. if (stats_var == compare_stats){
  1524. lcd.print("Temp is ok");
  1525. lcd.clear();
  1526. lcd.print("No action");}
  1527. if (stats_var < compare_stats){
  1528. lcd.print("Temp higher");
  1529. delay(1000);
  1530. lcd.clear();
  1531. lcd.print("Turning AC on...");
  1532. delay(1000);
  1533. sendDaewoo_ON();
  1534. lcd.clear();
  1535. lcd.print("AC on!");
  1536. lcd.setCursor(0,1);
  1537. lcd.print("<-:Back");}
  1538. if (stats_var > compare_stats){
  1539. lcd.print("Temp lower");
  1540. delay(1000);
  1541. lcd.clear();
  1542. lcd.print("Turning AC on...");
  1543. delay(1000);
  1544. sendDaewoo_ON();
  1545. lcd.clear();
  1546. lcd.print("AC on!");
  1547. lcd.setCursor(0,1);
  1548. lcd.print("<-:Back");}
  1549.  
  1550. while (activeButton == 0) {
  1551. int button;
  1552. readKey = analogRead(0);
  1553. if (readKey < 790) {
  1554. delay(100);
  1555. readKey = analogRead(0);
  1556. }
  1557. button = evaluateButton(readKey);
  1558. switch (button) {
  1559. case 4: // This case will execute if the "back" button is pressed
  1560. button = 0;
  1561. activeButton = 1;
  1562. break;
  1563. }
  1564. }
  1565. }
  1566. void TempD23() {
  1567. int activeButton = 0;
  1568.  
  1569. lcd.clear();
  1570. lcd.setCursor(0, 0);
  1571. lcd.print("Temp 23 selected");
  1572. delay(1000);
  1573. lcd.clear();
  1574. lcd.print("Scanning...");
  1575. stats_var=23;
  1576. compare_stats=Temperature_Scan();
  1577. delay(1000);
  1578. lcd.clear();
  1579. if (stats_var == compare_stats){
  1580. lcd.print("Temp is ok");
  1581. lcd.clear();
  1582. lcd.print("No action");}
  1583. if (stats_var < compare_stats){
  1584. lcd.print("Temp higher");
  1585. delay(1000);
  1586. lcd.clear();
  1587. lcd.print("Turning AC on...");
  1588. delay(1000);
  1589. sendDaewoo_ON();
  1590. lcd.clear();
  1591. lcd.print("AC on!");
  1592. lcd.setCursor(0,1);
  1593. lcd.print("<-:Back");}
  1594. if (stats_var > compare_stats){
  1595. lcd.print("Temp lower");
  1596. delay(1000);
  1597. lcd.clear();
  1598. lcd.print("Turning AC on...");
  1599. delay(1000);
  1600. sendDaewoo_ON();
  1601. lcd.clear();
  1602. lcd.print("AC on!");
  1603. lcd.setCursor(0,1);
  1604. lcd.print("<-:Back");}
  1605.  
  1606. while (activeButton == 0) {
  1607. int button;
  1608. readKey = analogRead(0);
  1609. if (readKey < 790) {
  1610. delay(100);
  1611. readKey = analogRead(0);
  1612. }
  1613. button = evaluateButton(readKey);
  1614. switch (button) {
  1615. case 4: // This case will execute if the "back" button is pressed
  1616. button = 0;
  1617. activeButton = 1;
  1618. break;
  1619. }
  1620. }
  1621. }
  1622. void TempD24() {
  1623. int activeButton = 0;
  1624.  
  1625. lcd.clear();
  1626. lcd.setCursor(0, 0);
  1627. lcd.print("Temp 24 selected");
  1628. delay(1000);
  1629. lcd.clear();
  1630. lcd.print("Scanning...");
  1631. stats_var=24;
  1632. compare_stats=Temperature_Scan();
  1633. delay(1000);
  1634. lcd.clear();
  1635. if (stats_var == compare_stats){
  1636. lcd.print("Temp is ok");
  1637. lcd.clear();
  1638. lcd.print("No action");}
  1639. if (stats_var < compare_stats){
  1640. lcd.print("Temp higher");
  1641. delay(1000);
  1642. lcd.clear();
  1643. lcd.print("Turning AC on...");
  1644. delay(1000);
  1645. sendDaewoo_ON();
  1646. lcd.clear();
  1647. lcd.print("AC on!");
  1648. lcd.setCursor(0,1);
  1649. lcd.print("<-:Back");}
  1650. if (stats_var > compare_stats){
  1651. lcd.print("Temp lower");
  1652. delay(1000);
  1653. lcd.clear();
  1654. lcd.print("Turning AC on...");
  1655. delay(1000);
  1656. sendDaewoo_ON();
  1657. lcd.clear();
  1658. lcd.print("AC on!");
  1659. lcd.setCursor(0,1);
  1660. lcd.print("<-:Back");}
  1661.  
  1662. while (activeButton == 0) {
  1663. int button;
  1664. readKey = analogRead(0);
  1665. if (readKey < 790) {
  1666. delay(100);
  1667. readKey = analogRead(0);
  1668. }
  1669. button = evaluateButton(readKey);
  1670. switch (button) {
  1671. case 4: // This case will execute if the "back" button is pressed
  1672. button = 0;
  1673. activeButton = 1;
  1674. break;
  1675. }
  1676. }
  1677. }
  1678. void TempD25() {
  1679. int activeButton = 0;
  1680.  
  1681. lcd.clear();
  1682. lcd.setCursor(0, 0);
  1683. lcd.print("Temp 25 selected");
  1684. delay(1000);
  1685. lcd.clear();
  1686. lcd.print("Scanning...");
  1687. stats_var=24;
  1688. compare_stats=Temperature_Scan();
  1689. delay(1000);
  1690. lcd.clear();
  1691. if (stats_var == compare_stats){
  1692. lcd.print("Temp is ok");
  1693. lcd.clear();
  1694. lcd.print("No action");}
  1695. if (stats_var < compare_stats){
  1696. lcd.print("Temp higher");
  1697. delay(1000);
  1698. lcd.clear();
  1699. lcd.print("Turning AC on...");
  1700. delay(1000);
  1701. sendDaewoo_ON();
  1702. lcd.clear();
  1703. lcd.print("AC on!");
  1704. lcd.setCursor(0,1);
  1705. lcd.print("<-:Back");}
  1706. if (stats_var > compare_stats){
  1707. lcd.print("Temp lower");
  1708. delay(1000);
  1709. lcd.clear();
  1710. lcd.print("Turning AC on...");
  1711. delay(1000);
  1712. sendDaewoo_ON();
  1713. lcd.clear();
  1714. lcd.print("AC on!");
  1715. lcd.setCursor(0,1);
  1716. lcd.print("<-:Back");}
  1717.  
  1718. while (activeButton == 0) {
  1719. int button;
  1720. readKey = analogRead(0);
  1721. if (readKey < 790) {
  1722. delay(100);
  1723. readKey = analogRead(0);
  1724. }
  1725. button = evaluateButton(readKey);
  1726. switch (button) {
  1727. case 4: // This case will execute if the "back" button is pressed
  1728. button = 0;
  1729. activeButton = 1;
  1730. break;
  1731. }
  1732. }
  1733. }
  1734. int Temperature_Scan() {
  1735. float f1 = dht.readTemperature(true);
  1736. float t_c;
  1737. t_c=(f1-36)*5/9;
  1738. return round(t_c);
  1739. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement