Components and supplies
Arduino Mega 2560
Project description
Code
Code version 2017-03
arduino
The date display now displays the day of the week - day - month. For example Mo 13 - 05 It should compile with Arduino IDE 1.6 up to 1.6.9, maybe not the newer versions of the IDE!! PLEASE note: the needed LIBRARIES are found as a ZIP file under "CUSTOM PARTS AND ENCLOSURES"
1/* 2 3 GorgyMeteoClock 4 5 2017-07-13 changing date display to also display day-of-the-week 6 2017-07-14 small edit: clear date display first and no decimal point 7 8 #### ###### ### #### 9 ## ## ##### ###### ## ## #### ## ## ####### #### ## ## ## ## ## ## ## 10 ## ## ## ## ## ### ## ## ## ## ## ## ## ## ## ## ## ## ## ## 11 ## ## ## ## ### ## ## ### ### ## ## #### ## ##### ##### ## ## 12 ## ## ##### ## ## # ## ## ## # ## ##### ## ## # ## ## ## ## ## ## 13 ## ## ## ## ## # ## ## ### ## # ## ## ## ### ###### ## ## ## ## ## ## 14 ## ## ## ## ## ## ### ## ## ## ## ## ## ## ## # ## ## ## ## ## ## ## 15 ##### ##### ###### ## ## ##### ## ## ####### ##### ### ## ###### #### #### #### 16 17*/ 18 19//---------------------------------------------------------------------------------------------------------- 20// Libraries 21//---------------------------------------------------------------------------------------------------------- 22// 23 24#include <SPI.h> // SPI interface library 25// -> http://arduino.cc/en/Reference/SPI 26#include <Time.h> // Arduino (new) Time library 27// -> http://www.pjrc.com/teensy/td_libs_Time.html 28#include <Timezone.h> // facilitate time zone conversions and automatic DST adjustments. 29//https://github.com/JChristensen/Timezone 30#include <Wire.h> // Enable this line if using Arduino Uno, Mega, etc. 31// 32#include <LedControl.h> // Maxim 7219 displays library 33// -> http://playground.arduino.cc/Main/LEDMatrix 34#include <OneWire.h> // OneWire lets you access 1-wire devices made by Maxim/Dallas, 35// such as DS18S20, DS18B20, DS1822. 36// http://www.pjrc.com/teensy/td_libs_OneWire.html 37// http://milesburton.com/Dallas_Temperature_Control_Library 38#include <IRremote.h> // 39#include "ClickButton.h" // A simple one-button Arduino library to get short and long clicks, 40// multiple clicks (double click, triple click etc.). 41// Click-and-hold is also possible. 42// -> https://code.google.com/p/clickbutton/ 43#include <Adafruit_GFX_AS.h> // Adafruit Core graphics library 44#include <Adafruit_ST7735_AS.h> // Adafruit 1.8" TFT 45#include "Adafruit_HTU21DF.h" // Adafruit HTU21D-F Temperature & Humidity Sensor 46#include <Streaming.h> 47#include <Adafruit_Sensor.h> // Adafruit Unified Sensor Driver 48#include <Adafruit_BMP183.h> // Adafruit BMP183 Barometric Pressure + Temp sensor 49#include "eeprom_routines.h" // EEprom routines for storing data 50//#include "RotaryEncoder.h" // smallest and best rotary lib I have seen... 51// https://code.google.com/p/arduino-rotary-encoder-with-velocity/ 52//---------------------------------------------------------------------------------------------------------- 53// I2C addresses 54//---------------------------------------------------------------------------------------------------------- 55#define CHRONODOT_ADDRESS 0x68 // Chronodot I2C address 56#define BH1750_ADDRESS 0x23 // BH1750 Lux Sensor I2C address 57#define TSL2561_ADDRESS 0x39 // Lux Sensor I2C address 58#define HTU21DF_ADDRESS 0x40 // Humidity Sensor I2C address 59#define EEPROM_ADDRESS 0x50 // EEprom address for storing barametric array data etc. 60 61//---------------------------------------------------------------------------------------------------------- 62// Humidity Sensor init 63//---------------------------------------------------------------------------------------------------------- 64Adafruit_HTU21DF htu21df = Adafruit_HTU21DF(); 65 66//---------------------------------------------------------------------------------------------------------- 67// Barometric pressure sensor init 68//---------------------------------------------------------------------------------------------------------- 69#define BMP183_CLK 52 // SCK to SPI Clock 70#define BMP183_SDO 50 // MISO 71#define BMP183_SDI 51 // MOSI 72#define BMP183_CS 42 // CS: Chip Select Pin 73// initialize BMP183 sensor with hardware SPI 74Adafruit_BMP183 bmp183 = Adafruit_BMP183(BMP183_CS); 75 76// or initialize with software SPI and use any 4 pins 77// CLK SDO SDI CS); 78//Adafruit_BMP183 bmp = Adafruit_BMP183( 3, 6, 2, 7); 79 80//---------------------------------------------------------------------------------------------------------- 81// DS18B20 initialization 82//---------------------------------------------------------------------------------------------------------- 83OneWire ds(46); // define Onewire instance DS 84// address: 0x28, 0xF0, 0xEC, 0xE2, 0x04, 0x00, 0x00, 0x47 85 86//---------------------------------------------------------------------------------------------------------- 87// IRreceiver initialization 88//---------------------------------------------------------------------------------------------------------- 89IRrecv irrecv(44); 90decode_results irReceive; 91 92//---------------------------------------------------------------------------------------------------------- 93// Adafruit 1.8" TFT display init 94//---------------------------------------------------------------------------------------------------------- 95//Connect to hardware SPI on Mega2560: 96 97#define sclk 52 // Uno:13 // Don't change 98#define mosi 51 // Uno:11 // Don't change 99#define cs 48 // Uno:9 100#define dc 49 // Uno:8 101#define rst 47 // Uno:7 // you can also connect this to the Arduino reset 102 103Adafruit_ST7735_AS tft = Adafruit_ST7735_AS(cs, dc, rst); // Invoke custom library 104 105// or use any pins but a little slower 106// cs dc mosi sclk, rst); 107//Adafruit_ST7735 tft = Adafruit_ST7735(10, 9, 11, 13, 8); 108 109// define colors for TFTdisplay 110#define BLACK 0x0000 111#define BLUE 0x001F 112#define RED 0xF800 113#define ORANGE 0xFD20 114#define GREEN 0x07E0 115#define CYAN 0x07FF 116#define MAGENTA 0xF81F 117#define YELLOW 0xFFE0 118#define WHITE 0xFFFF 119#define LGRAY 0xC618 120#define DGRAY 0x8410 121 122//---------------------------------------------------------------------------------------------------------- 123// Maxim 7219 Matrix Display initialization 124//---------------------------------------------------------------------------------------------------------- 125//***** Please set the number of devices you have ***** 126// But the maximum default of 8 MAX72XX wil also work. 127// LedConrol( DATAIN(SDI/MOSI), CLOCK, CS/LOAD , NUMBER OF MAXIM CHIPS,) 128LedControl maxim = LedControl(40, 36, 38, 3, false); // Define pins for Maxim 72xx and how many 72xx we use 129//LedControl maxim = LedControl(40, 39, 38, 3, false); // Define pins for Maxim 72xx and how many 72xx we use 130//LedControl maxim = LedControl(11, 13, 6, 1, false); // Define pins for Maxim 72xx and how many 72xx we use 131 132//---------------------------------------------------------------------------------------------------------- 133// Rotary encoder 134//---------------------------------------------------------------------------------------------------------- 135//RotaryEncoder encoder(A0,A1,1,1,1); 136//#define BUTTON_SELECT_PIN A2 137 138//---------------------------------------------------------------------------------------------------------- 139// Miscellaneous 140//---------------------------------------------------------------------------------------------------------- 141// Adafruit TFT screen things 142#if defined(__SAM3X8E__) 143#undef __FlashStringHelper::F(string_literal) 144#define F(string_literal) string_literal 145#endif 146 147//---------------------------------------------------------------------------------------------------------- 148// Daylight Savings Time calculation parameters 149//---------------------------------------------------------------------------------------------------------- 150//Europe, Amsterdam Time Zone (ZT = DST, WT = DST) 151TimeChangeRule myZT = {"ZT", Last, Sun, Mar, 2, +120}; //Daylight time = UTC +2 hours 152TimeChangeRule myWT = {"WT", Last, Sun, Oct, 3, +60}; //Standard time = UTC +1 hours 153Timezone myTZ(myZT, myWT); 154 155//---------------------------------------------------------------------------------------------------------- 156// RTC DS3231 stuff 157//---------------------------------------------------------------------------------------------------------- 158// set SQW output DS3231 RTC chip 159#define SQW_FREQ SQWAVE_1_HZ // 0b00000000 1Hz 160//#define SQW_FREQ SQWAVE_4096_HZ // 0b00001000 1024Hz 161//#define SQW_FREQ SQWAVE_1024_HZ // 0b00010000 4096Hz 162//#define SQW_FREQ SQWAVE_8192_HZ // 0b00010000 4096Hz 163//#define SQW_FREQ SQWAVE_NONE // DISABLE 164 165 166//---------------------------------------------------------------------------------------------------------- 167// EEPROM 168//---------------------------------------------------------------------------------------------------------- 169// memory start address to for barometer array data 170#define BAROGRAPH_START_ADDRESS 100 171 172 173//---------------------------------------------------------------------------------------------------------- 174// Variable and array defenitions 175//---------------------------------------------------------------------------------------------------------- 176// define Maxim 7219 display parameters 177#define TIMEDISPLAY 1 // first Maxim 7219 in 'daisychain' must be '0', next '1' etc. 178#define SECONDSDISPLAY 2 // first Maxim 7219 in 'daisychain' must be '0', next '1' etc. 179#define DATEDISPLAY 0 180 181//---------------------------------------------------------------------------------------------------------- 182// LED pins 183//---------------------------------------------------------------------------------------------------------- 184#define ERRORLED 36 185 186//---------------------------------------------------------------------------------------------------------- 187// PWM brightness ports 188//---------------------------------------------------------------------------------------------------------- 189#define MARKERS_HOURS 10 // PWM 190#define MARKERS_MINUTES 11 // PWM 191#define TFT_LIGHT 12 // Lite - this is the PWM input for the backlight control. Connect to 3-5VDC to turn on the 192// backlight. Connect to ground to turn it off. Or, you can PWM at any frequency. 193//---------------------------------------------------------------------------------------------------------- 194// Buttons definition 195//---------------------------------------------------------------------------------------------------------- 196// create 3 Clickbutton instances, one for each button 197#define BUTTON_SELECT_PIN A0 198#define BUTTON_UP_PIN A1 199#define BUTTON_DOWN_PIN A2 200 201ClickButton buttonUp(BUTTON_UP_PIN, LOW, CLICKBTN_PULLUP); 202ClickButton buttonDown(BUTTON_DOWN_PIN, LOW, CLICKBTN_PULLUP); 203ClickButton buttonSelect(BUTTON_SELECT_PIN, LOW, CLICKBTN_PULLUP); 204 205 206//// user input actions 207//enum {NO_ACTION, BTN_CLICK, BTN_DOUBLE_CLICK, BTN_HOLD, ROTATE_L, ROTATE_R}; // used for rotary 208enum {NO_ACTION, BTN_SELECT, BTN_SELECT_HOLD, BTN_UP, BTN_DOWN, LED_RING_MODE, MEMORY_RESET, EEPROM_WRITE_BARO, EEPROM_READ_BARO}; 209//---------------------------------------------------------------------------------------------------------- 210// Related to the State Machine 211//---------------------------------------------------------------------------------------------------------- 212// The different states of the system 213enum states 214{ 215 STATE_MAIN, 216 STATE_TEMP_DISPLAY, 217 STATE_HUMIDITY_DISPLAY, 218 STATE_TIME_DETAIL, 219 STATE_BAROGRAPH, 220 STATE_BAROGRAPH_TREND, 221 STATE_MENU_ALARM_TIME, 222 STATE_MENU_SET_ALARM_HOUR, 223 STATE_MENU_SET_ALARM_MINUTES, 224 STATE_MENU_SECONDS_RING, 225 STATE_MENU_SET_SECONDS_RING_MODE, 226 STATE_MENU_LCD_MODE, 227 STATE_MENU_SET_LCD_MODE, 228 STATE_MENU_TIME, 229 STATE_MENU_SET_TIME_HOUR, 230 STATE_MENU_SET_TIME_MINUTES, 231 STATE_MENU_DATE, 232 STATE_MENU_SET_DAY, 233 STATE_MENU_SET_MONTH, 234 STATE_MENU_SET_YEAR, 235 STATE_MENU_BAROGRAPH, 236 STATE_MENU_SET_SEA_LEVEL_PRESSURE, 237 STATE_MENU_SET_PRESSURE_CORRECTION, 238}; 239states currState; // Holds the current state of the system 240 241/*************************************************************************************************************************************************** 242 243 ## ## ## ###### ###### ## ###### ## ####### ##### 244 ## ## ## ## ## ## ## ## ## ## ## ## ## 245 ## ## #### ## ## ## #### ## ## ## ## ## 246 ## ## ## # ###### ## ## # ###### ## ##### ##### 247 ## ## ###### ## ## ## ###### ## ## ## ## ## 248 ### ## # ## ## ## ## # ## ## ## ## ## ## 249 ### ### ## ## ## ###### ### ## ###### ###### ####### ##### 250 251****************************************************************************************************************************************************/ 252#define plotLimitH 130 // graph plotlimit Horizontal 253#define plotRangeH 130 // graph plot size Horizontal 254#define plotLimitV 115 // graph plotlimit Vertical 255#define plotRangeV 100 // graph plot size Vertical 256// Horizontal Grid lines 257#define grid24HstartpositionXaxis 0 258#define grid24HstartpositionYaxis 15 259#define grid24HlineSpacing 20 260#define grid24HlinePixelSpacing 2 261#define grid24HlinePixelSpacing1H 5 262#define grid24HlinePixelSpacing2H 10 263#define grid24HlinePixelSpacing4H 20 264#define grid24XaxisTicksStart 5 265// Vertical Grid lines 266#define grid24VstartpositionXaxis 10 267#define grid24VstartpositionYaxis 15 268#define grid24VlineSpacing 20 269#define grid24VlinePixelSpacing 2 270#define grid24VlinePixelSpacing10Hpa 20 271#define grid24VlinePixelSpacing5Hpa 10 272 273#define GRIDCOLOR LGRAY 274#define PLOTCOLOR BLUE 275#define XAXISCOLOR WHITE 276#define YAXISCOLOR WHITE 277#define XTEXTCOLOR WHITE 278#define YTEXTCOLOR WHITE 279#define PRESSUREVALUECOLOR GREEN 280#define TEMPVALUECOLOR MAGENTA 281#define HYGROVALUECOLOR ORANGE 282 283char* strDOW[8] = {"null", "Zondag", "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag"}; 284int strDOWlength[8] = {0, 6, 7, 7, 8, 9, 7, 8}; 285char* strMonth[13] = {"null", "Jan", "Feb", "Mrt", "Apr", "Mei", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"}; 286//char* strMonth[13] = {"null","Januari","Februari","Maart","April","Mei","Juni","Juli","Augustus","September","Oktober","November","December"}; 287 288 289byte readWeatherdataInterval = 12; 290 291bool secondsRingUpdated = false; 292bool tftMainUpdated = false; 293bool tftTimeUpdated = false; 294bool tftBarographUpdated = false; 295bool tftBaroTrendUpdated = false; 296 297 298 299int baroTrendValue = 0; 300int baroTrend = 0; 301enum {NA, ZEER_SNEL_DALEND, SNEL_DALEND, DALEND, LANGZAAM_DALEND, STABIEL, LANGZAAM_STIJGEND, STIJGEND, SNEL_STIJGEND, ZEER_SNEL_STIJGEND}; 302bool pressureDataUpdated = false; 303bool pressureDataStored = false; 304bool pressureDataToEEprom = false; 305bool pressureDataFromEEprom = false; 306long pressureSample = 0; 307long pressure = 0; 308long pressureMin = 0; 309long pressureMax = 0; 310int minPressureHour = 0; 311int minPressureMinute = 0; 312int maxPressureHour = 0; 313int maxPressureMinute = 0; 314 315 316int testpressure = 980; 317int step = 5; 318int previousPressureMin = 0; 319int previousPressureMax = 0; 320int meanSeaLevelPressure = 10155; 321int pressureCorrection = 2; 322bool resetBarograph = false; 323 324int countdown = 10800; 325 326int x = 0; 327int plotvalueP = 0; 328int plotvalueP1 = 0; 329int plotvalueT = 0; 330bool highScale = false; 331bool currentScale = false; 332int barometerData[132]; // array to hold barometric data 333unsigned int readings = 0; 334int pressureHourAvarage[130]; 335int pressureHourlyTrend = 0; 336 337unsigned long timer1 = millis(); 338unsigned long lastRotation = millis(); 339unsigned long lastUpdate1 = millis(); 340bool startup = true; 341int q; 342 343 344// Humidity related variables 345int humidity = 0; 346int climateComfort = 0; 347int minHumidity = 0; 348int maxHumidity = 0; 349int minHumidityHour = 0; 350int minHumidityMinute = 0; 351int maxHumidityHour = 0; 352int maxHumidityMinute = 0; 353bool humidityMemoryReset = false; 354 355#define ccRED 0 356#define ccYELLOW 1 357#define ccGREEN 2 358 359 360// temperature variables 361bool temperatureMemoryReset = true; 362int tempCelcius = 0; 363int minTemp = 0; 364int maxTemp = 0; 365int minTempHour = 0; 366int minTempMinute = 0; 367int maxTempHour = 0; 368int maxTempMinute = 0; 369//@1 370byte tCount; 371byte present = 0; 372byte data[12]; 373byte addr[8] = {0x28, 0xF0, 0xEC, 0xE2, 0x04, 0x00, 0x00, 0x47}; 374 375 376// Time related variables 377bool setSecondsToZero = false; 378int previousDay = 0; 379int lastMinute = 0; 380time_t t; 381byte previousSecond = 0; 382byte previousMinute = 0; 383byte previousHour = 0; 384int TMPsecond; // holds time & date while setting the time 385int TMPminute; 386int TMPhour; 387int TMPweekday; 388int TMPday; 389int TMPmonth; 390int TMPyear; 391int daylightSavingTime = 0; 392bool daylightSavingTimeHasChanged = false; 393boolean RTCERROR = true; // flag to check RTC communication, used in SHOW_TIME_DATE_WEATHER_DATE_WEATHER and SHOW_DATE 394short dayNumber; //Returns the number of day in the year 395short weekNumber; //Returns the number of the week in the year 396 397byte alarmHour = 8; 398byte alarmMinute = 30; 399 400 401bool sw1 = true; 402bool stateChange = false; 403int userAction = 0; 404int previousMenu = 0; 405volatile unsigned long timeOfLastButtonPress = 0; 406bool secondsRingFull = true; 407bool lcdScrollModeAuto = false; 408bool needToSaveTime = false; 409bool needToUpdateBarograph = false; 410bool needToUpdateTFT = false; 411bool isWaitingforTimeout = false; 412 413//Brightness 414byte brightnessTimeDisplay = 1; // value from 0-15 415byte brightnessSecondsRing = 0; // value from 0-15 416byte brightnessDateDisplay = 3; // value from 0-15 417byte brightnessMinuteMarkers = 505; // USE PWM value from 0 - 512, higher is dimmer 418byte brightnessHourMarkers = 512; // USE PWM value from 0 - 512 419byte brightnessLcdBacklight = 420; // USE PWM value from 0 - 512 420 421 422bool irRemote = false; 423 424byte ledRingMode = 0; 425bool ledRingModeIsChanged = false; 426 427int sec = 0; 428 429 430 431// Define Interrupt function 432 433volatile boolean updateTime = false; 434 435// DS3231 1Hz pulse ISR 436void pulseISR() 437{ 438 updateTime = true; 439} 440 441 442 443 444 445 446 447 448 449 450/*************************************************************************************************************************************************** 451 452 ## ## 453 ##### ####### ###### ## ## ###### ## ## 454 ## ## ## ## ## ## ## ## ## ## 455 ## ## ## ## ## ## ## ## ## 456 ##### ##### ## ## ## ###### ## ## 457 ## ## ## ## ## ## ## ## 458 ## ## ## ## ## ## ## ## ## 459 ##### ####### ## ##### ## ## ## 460 ## ## 461 462****************************************************************************************************************************************************/ 463 464 465void setup() 466{ 467 //DEBUG 468 pinMode(A8, OUTPUT); 469 pinMode(A9, OUTPUT); 470 pinMode(A10, OUTPUT); 471 pinMode(A11, OUTPUT); 472 //END DEBUG ;) 473 474 475 pinMode(ERRORLED, OUTPUT); 476 pinMode(TFT_LIGHT, OUTPUT); 477 pinMode(MARKERS_HOURS, OUTPUT); 478 pinMode(MARKERS_MINUTES, OUTPUT); 479 pinMode(53, OUTPUT); // Set to OUTPUT NEEDED FOR SPI HARDWARE MASTER MODE 480 481 Wire.begin(); // start I2C 482 irrecv.enableIRIn(); // Start the IR remote receiver 483 484 Serial.begin(115200); // start Serial for debug purposes 485 486 //RTC.squareWave(SQW_FREQ); // Set RTC DS3231 SQW frequency (1 Hz in this case) 487 attachInterrupt(0, pulseISR, RISING); // DS3231 sends an 1Hz pulse - we use this to update the display 488 489 readRTC(); 490 setTime(TMPhour, TMPminute, TMPsecond, TMPday, TMPmonth, TMPyear); 491 492 //setTime(2, 59, 45, 25, 10, 15); // test for change to winter time 493 //setTime(1, 59, 45, 29, 3, 15); // test for change to summer time 494 //timeDateToTemporaryMem(); 495 //writeRTC(); 496 497 // store current DST value in variable to check if DST is changed 498 daylightSavingTime = myTZ.locIsDST(now()); 499 500 501 //setTime(RTC.get()); 502 //setSyncProvider(RTC.get); // set RTC as the Syncprovider 503 //setSyncInterval(5); // time in sec of resync with RTC 504 505 // clear barometer pressure data array 506 for (int i = 0; i <= 130; i++) 507 { 508 barometerData[i] = 0; 509 } 510 511 initTFT(); // Initialize the TFT screen 512 clearTFT(); 513 init7SegDisplay(); // initialize 7 segment display 514 initHumiditySensor(); // start Humidity Sensor 515 initBaroSensor(); // initialize Pressure sensor 516 brightnessAdj(); 517 518 requestTemperature(); 519 readHumidity(); 520 521 // initialize array 522 for (int i = 0; i < 133; i++) 523 { 524 barometerData[i] = 0; 525 } 526 527 currState = STATE_MAIN; // Initial state of the FSM 528 529} 530 531 532 533/*************************************************************************************************************************************************** 534 535 ## ## 536 ## ### ### ###### ## ## 537 ## ## ## ## ## ## ## ## ## 538 ## ## ## ## ## ## ## ## ## 539 ## ## ## ## ## ###### ## ## 540 ## ## ## ## ## ## ## ## 541 ## ## ## ## ## ## ## ## 542 ###### ### ### ## ## ## 543 ## ## 544 545****************************************************************************************************************************************************/ 546 547 548void loop() 549{ 550 551 552 if (updateTime == true) 553 { 554 updateTime = false; 555 executeState(); 556 } 557 558 userAction = checkUserAction(); 559 if (userAction != NO_ACTION) // user has pressed a button 560 { 561 processAction(userAction); 562 } 563 else if (isWaitingforTimeout == true && millis() - timeOfLastButtonPress > 5000) 564 { 565 isWaitingforTimeout = false; 566 clearTFT(); 567 clearTimeDisplay(); 568 clearDateDisplay(); 569 clearSecondsDisplay(); 570 startup = true; 571 currState = STATE_MAIN; 572 } 573 574} 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590/*************************************************************************************************************************************************** 591 592 #### ## ## ## ## ## ## ##### ####### ###### ## #### ###### ###### ### ## ## 593 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ### ## 594 ## ## ## ## ## ## ## ## ## ## ## #### ## ## ## ## ## ### ## 595 ## ####### #### ## ## ##### ##### ###### ## # ## ## ## ## ## ## # ## 596 ## ## ## ## ## ## ## ## ## ## ## ###### ## ## ## ## ## ## # ## 597 ## ## ## ## ## ## ## ## ## ## ## ## ## ## # ## ## ## ## ## ## ## ### 598 #### ## ## ## ## ##### ##### ####### ## ## ### ## #### ## ###### ### ## ## 599 600****************************************************************************************************************************************************/ 601// check for user input 602int checkUserAction() 603{ 604 ////////////////////////////////// 605 // check for IR remote commands // 606 ////////////////////////////////// 607 if (irrecv.decode(&irReceive)) 608 { 609 switch (irReceive.value) 610 { 611 case 0x1C3B939F: // "Menu" key 612 userAction = BTN_SELECT_HOLD; 613 irRemote = true;// needed to check for IR input! 614 break; 615 616 case 0x75E8EBA3: // "Select" key 617 userAction = BTN_SELECT; 618 irRemote = true; 619 break; 620 621 case 0x150ADC43: // "Up" key 622 userAction = BTN_UP; 623 irRemote = true; 624 break; 625 626 case 0xA8A8B363: // "Play" 627 628 irRemote = true; 629 break; 630 631 case 0x6551963F: // "Down" 632 userAction = BTN_DOWN; 633 irRemote = true; 634 break; 635 636 case 0x2560B67: // "+" key 637 userAction = EEPROM_WRITE_BARO; 638 irRemote = true; 639 break; 640 641 case 0x5655FCFF: // "-" key 642 userAction = EEPROM_READ_BARO; 643 irRemote = true; 644 break; 645 646 case 0x3C1B0E83: // "|<<" key 647 648 break; 649 650 case 0xB55AE2FF: // ">>|" key 651 readArray(); // Debug. read array and display on Serial Monitor 652 readRTC(); // DEBUG. read RTC time and update system time 653 setTime(TMPhour, TMPminute, TMPsecond, TMPday, TMPmonth, TMPyear); 654 break; 655 656 case 0xD293DA9F: // "Spatial" key 657 userAction = MEMORY_RESET; 658 irRemote = true; 659 break; 660 661 case 0xF761B2A3: // "Power" key 662 663 break; 664 665 case 0x12284AC3: // "Shuffle" key 666 667 break; 668 669 case 0x509BADB: // "Repeat" key 670 userAction = LED_RING_MODE; 671 irRemote = true; 672 ledRingModeIsChanged = true; 673 break; 674 }// switch 675 676 //Serial.println(results.value, HEX); 677 irrecv.resume(); // Receive the next value 678 } 679 680 // if IR remote is used, activate time-out function, used in the settings menu 681 if (irRemote == true) 682 { 683 irRemote = false; 684 timeOfLastButtonPress = millis(); 685 return userAction; 686 } 687 688 //////////////////////////// 689 // check for button input // 690 //////////////////////////// 691 692 // no IR signals received, next check for button input 693 694 // check state of each button 695 buttonUp.Update(); 696 buttonDown.Update(); // 1 = short click, -1 = long click (>1 second) 697 buttonSelect.Update(); // 0 = no input, Duh! 698 699 if (buttonSelect.clicks != 0) // check for user action of SELECT BUTTON 700 { 701 int clicks = buttonSelect.clicks; 702 if (clicks > 1) clicks = 1; // no double clicks... 703 704 switch (clicks) 705 { 706 case 1: // Select button is pressed 1x 707 userAction = BTN_SELECT; 708 break; 709 710 case -1: // Select button is pressed 1x for > 1 second 711 userAction = BTN_SELECT_HOLD; 712 break; 713 } 714 } 715 else if (buttonUp.clicks == 1) // check for user action of UP BUTTON 716 { 717 userAction = BTN_UP; 718 } 719 else if (buttonDown.clicks == 1) // check for user action of DOWN BUTTON 720 { 721 userAction = BTN_DOWN; 722 } 723 // no IR commands or button press 724 else 725 { 726 userAction = NO_ACTION; 727 } 728 729 if (userAction != NO_ACTION) 730 { 731 timeOfLastButtonPress = millis(); 732 } 733 734 return userAction; 735} 736 737/*************************************************************************************************************************************************** 738 739 ###### ###### ### #### ####### ##### ##### ## #### ###### ###### ### ## ## 740 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ### ## 741 ## ## ## ## ## ## ## ## ## ## #### ## ## ## ## ## ### ## 742 ###### ###### ## ## ## ##### ##### ##### ## # ## ## ## ## ## ## # ## 743 ## ## ## ## ## ## ## ## ## ###### ## ## ## ## ## ## # ## 744 ## ## ## ## ## ## ## ## ## ## ## ## ## # ## ## ## ## ## ## ## ### 745 ## ## ## ### #### ####### ##### ##### ### ## #### ## ###### ### ## ## 746 747****************************************************************************************************************************************************/ 748// change state of the "state machine" based on the user input; 749// also perform one-time actions required by the change of state (e.g. clear display); 750void processAction(int userAction) 751{ 752 // Uses the current state to decide what to process 753 switch (currState) 754 { 755 case STATE_MAIN: //---------------------{ 0 }--{ STATE MAIN }-------------------- 756 757 if (userAction == BTN_SELECT_HOLD) 758 { 759 currState = STATE_MENU_ALARM_TIME; 760 stateChange = true; 761 isWaitingforTimeout = true; 762 clearTFT(); 763 clearTimeDisplay(); 764 clearDateDisplay(); 765 clearSecondsDisplay(); 766 drawSettingsMenu(); 767 } 768 769 if (userAction == BTN_DOWN) 770 { 771 clearTFT(); 772 currState = STATE_TEMP_DISPLAY; 773 stateChange = true; 774 } 775 776 if (userAction == BTN_UP) 777 { 778 clearTFT(); 779 currState = STATE_BAROGRAPH_TREND; 780 stateChange = true; 781 } 782 783 if (userAction == LED_RING_MODE) 784 { 785 ledRingMode++; 786 if (ledRingMode > 3) 787 { 788 ledRingMode = 0; 789 } 790 } 791 792 break; 793 case STATE_TEMP_DISPLAY: //---------------------{ 1 }--{ STATE TEMP DISPLAY }-------------------- 794 795 if (userAction == BTN_SELECT_HOLD) 796 { 797 currState = STATE_MENU_ALARM_TIME; 798 stateChange = true; 799 isWaitingforTimeout = true; 800 clearTFT(); 801 clearTimeDisplay(); 802 clearDateDisplay(); 803 clearSecondsDisplay(); 804 drawSettingsMenu(); 805 } 806 807 if (userAction == BTN_DOWN) 808 { 809 clearTFT(); 810 currState = STATE_HUMIDITY_DISPLAY; 811 stateChange = true; 812 } 813 814 if (userAction == BTN_UP) 815 { 816 clearTFT(); 817 currState = STATE_MAIN; 818 stateChange = true; 819 } 820 821 if (userAction == LED_RING_MODE) 822 { 823 ledRingMode++; 824 if (ledRingMode > 3) 825 { 826 ledRingMode = 0; 827 } 828 } 829 830 if (userAction == MEMORY_RESET) 831 { 832 temperatureMemoryReset = true; 833 minTemp = maxTemp = tempCelcius; 834 minTempHour = maxTempHour = hour(); 835 minTempMinute = maxTempMinute = minute(); 836 } 837 838 break; 839 case STATE_HUMIDITY_DISPLAY: //---------------------{ 2 }--{ STATE HUMIDITY DISPLAY }-------------------- 840 841 if (userAction == BTN_SELECT_HOLD) 842 { 843 currState = STATE_MENU_ALARM_TIME; 844 stateChange = true; 845 isWaitingforTimeout = true; 846 clearTFT(); 847 clearTimeDisplay(); 848 clearDateDisplay(); 849 clearSecondsDisplay(); 850 drawSettingsMenu(); 851 } 852 853 if (userAction == BTN_DOWN) 854 { 855 clearTFT(); 856 currState = STATE_TIME_DETAIL; 857 stateChange = true; 858 } 859 860 if (userAction == BTN_UP) 861 { 862 clearTFT(); 863 currState = STATE_TEMP_DISPLAY; 864 stateChange = true; 865 } 866 867 if (userAction == LED_RING_MODE) 868 { 869 ledRingMode++; 870 if (ledRingMode > 3) 871 { 872 ledRingMode = 0; 873 } 874 } 875 876 if (userAction == MEMORY_RESET) 877 { 878 humidityMemoryReset = true; 879 minHumidity = maxHumidity = humidity; 880 minHumidityHour = maxHumidityHour = hour(); 881 minHumidityMinute = maxHumidityMinute = minute(); 882 } 883 884 break; 885 case STATE_TIME_DETAIL: //---------------------{ 3 }--{ STATE TIME DETAIL }-------------------- 886 887 if (userAction == BTN_SELECT_HOLD) 888 { 889 currState = STATE_MENU_ALARM_TIME; 890 stateChange = true; 891 isWaitingforTimeout = true; 892 clearTFT(); 893 clearTimeDisplay(); 894 clearDateDisplay(); 895 clearSecondsDisplay(); 896 drawSettingsMenu(); 897 } 898 899 if (userAction == BTN_DOWN) 900 { 901 clearTFT(); 902 currState = STATE_BAROGRAPH; 903 stateChange = true; 904 } 905 906 if (userAction == BTN_UP) 907 { 908 clearTFT(); 909 currState = STATE_HUMIDITY_DISPLAY; 910 stateChange = true; 911 } 912 913 if (userAction == MEMORY_RESET) 914 { 915 setSecondsToZero = true; 916 } 917 918 if (userAction == LED_RING_MODE) 919 { 920 ledRingMode++; 921 if (ledRingMode > 3) 922 { 923 ledRingMode = 0; 924 } 925 } 926 927 break; 928 case STATE_BAROGRAPH: //---------------------{ 4 }--{ STATE BAROGRAPH }-------------------- 929 930 if (userAction == BTN_SELECT_HOLD) 931 { 932 currState = STATE_MENU_ALARM_TIME; 933 stateChange = true; 934 isWaitingforTimeout = true; 935 clearTFT(); 936 clearTimeDisplay(); 937 clearDateDisplay(); 938 clearSecondsDisplay(); 939 drawSettingsMenu(); 940 } 941 942 if (userAction == BTN_DOWN) 943 { 944 clearTFT(); 945 currState = STATE_BAROGRAPH_TREND; 946 stateChange = true; 947 } 948 949 if (userAction == BTN_UP) 950 { 951 clearTFT(); 952 currState = STATE_TIME_DETAIL; 953 stateChange = true; 954 } 955 956 if (userAction == EEPROM_WRITE_BARO) 957 { 958 // + button of remote pressed: store barometer pressur data array in EEPROM 959 pressureDataToEEprom = true; 960 } 961 962 if (userAction == EEPROM_READ_BARO) 963 { 964 // + button of remote pressed: store barometer pressur data array in EEPROM 965 pressureDataFromEEprom = true; 966 } 967 968 if (userAction == LED_RING_MODE) 969 { 970 ledRingMode++; 971 if (ledRingMode > 3) 972 { 973 ledRingMode = 0; 974 } 975 } 976 977 break; 978 case STATE_BAROGRAPH_TREND: //---------------------{ 5 }--{ STATE BAROGRAPH TREND }-------------------- 979 980 if (userAction == BTN_SELECT_HOLD) 981 { 982 currState = STATE_MENU_ALARM_TIME; 983 stateChange = true; 984 isWaitingforTimeout = true; 985 clearTFT(); 986 clearTimeDisplay(); 987 clearDateDisplay(); 988 clearSecondsDisplay(); 989 drawSettingsMenu(); 990 } 991 992 if (userAction == BTN_DOWN) 993 { 994 clearTFT(); 995 currState = STATE_MAIN; 996 stateChange = true; 997 } 998 999 if (userAction == BTN_UP) 1000 { 1001 clearTFT(); 1002 currState = STATE_BAROGRAPH; 1003 stateChange = true; 1004 } 1005 1006 if (userAction == LED_RING_MODE) 1007 { 1008 ledRingMode++; 1009 if (ledRingMode > 3) 1010 { 1011 ledRingMode = 0; 1012 } 1013 } 1014 1015 1016 break; 1017 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 1018 case STATE_MENU_ALARM_TIME: //--------------------{ 6 }--{ STATE MENU ALARM TIME }-------------------- 1019 1020 if (userAction == BTN_SELECT) 1021 { 1022 //currState = STATE_MENU_SET_ALARM_HOUR; 1023 previousMenu = 5; 1024 stateChange = true; 1025 } 1026 1027 if (userAction == BTN_UP) 1028 { 1029 // exit menu 1030 } 1031 1032 if (userAction == BTN_DOWN) 1033 { 1034 currState = STATE_MENU_SECONDS_RING; 1035 previousMenu = 5; 1036 stateChange = true; 1037 // restore menu item 1038 drawSettingsMenuAlarmTime(); 1039 // highlight new menu item 1040 drawSettingsMenuSecondsRing(); 1041 } 1042 1043 1044 1045 break; 1046 1047 case STATE_MENU_SET_ALARM_HOUR: //---------------------{ 7 }--{ MENU SET ALARM HOUR }-------------------- 1048 1049 break; 1050 1051 case STATE_MENU_SET_ALARM_MINUTES: //---------------------{ 8 }--{ MENU SET ALARM MINUTES }----------------- 1052 1053 break; 1054 1055 case STATE_MENU_SECONDS_RING: //---------------------{ 9 }--{ MENU SECONDS RING }---------------------- 1056 1057 if (userAction == BTN_SELECT) 1058 { 1059 //currState = STATE_MENU_SET_SECONDS_RING_MODE; 1060 previousMenu = 8; 1061 stateChange = true; 1062 } 1063 1064 if (userAction == BTN_UP) 1065 { 1066 currState = STATE_MENU_ALARM_TIME; 1067 previousMenu = 8; 1068 stateChange = true; 1069 // restore menu item 1070 drawSettingsMenuSecondsRing(); 1071 // highlight new menu item 1072 drawSettingsMenuAlarmTime(); 1073 } 1074 1075 if (userAction == BTN_DOWN) 1076 { 1077 currState = STATE_MENU_LCD_MODE; 1078 previousMenu = 8; 1079 stateChange = true; 1080 // restore menu item 1081 drawSettingsMenuSecondsRing(); 1082 // highlight new menu item 1083 drawSettingsMenuLcdMode(); 1084 } 1085 1086 break; 1087 1088 case STATE_MENU_SET_SECONDS_RING_MODE: //--------------------{ 10 }--{ MENU_SET_SECONDS_RING_MODE }------------- 1089 1090 break; 1091 1092 case STATE_MENU_LCD_MODE: //--------------------{ 11 }--{ MENU_LCD_MODE }-------------------------- 1093 1094 if (userAction == BTN_SELECT) 1095 { 1096 currState = STATE_MENU_SET_SECONDS_RING_MODE; 1097 previousMenu = 8; 1098 stateChange = true; 1099 } 1100 1101 if (userAction == BTN_UP) 1102 { 1103 currState = STATE_MENU_SECONDS_RING; 1104 previousMenu = 10; 1105 stateChange = true; 1106 // restore menu item 1107 drawSettingsMenuLcdMode(); 1108 // highlight new menu item 1109 drawSettingsMenuSecondsRing(); 1110 } 1111 1112 if (userAction == BTN_DOWN) 1113 { 1114 currState = STATE_MENU_TIME; 1115 previousMenu = 10; 1116 stateChange = true; 1117 // restore menu item 1118 drawSettingsMenuLcdMode(); 1119 // highlight new menu item 1120 drawSettingsMenuTimeSet(); 1121 } 1122 1123 break; 1124 1125 case STATE_MENU_SET_LCD_MODE: //--------------------{ 12 }--{ MENU_SET_LCD_MODE }---------------------- 1126 1127 break; 1128 1129 case STATE_MENU_TIME: //--------------------{ 13 }--{ MENU_TIME}---------------------- 1130 1131 if (userAction == BTN_SELECT) 1132 { 1133 //transfer time/date info in temporary variables 1134 timeDateToTemporaryMem(); 1135 // HOUR variable: set red background 1136 tft.setCursor(1, 86); 1137 tft.setTextColor(WHITE, RED); 1138 TMPhour < 10 ? (tft << " " << TMPhour) : tft << TMPhour; 1139 1140 currState = STATE_MENU_SET_TIME_HOUR; 1141 previousMenu = 12; 1142 stateChange = true; 1143 } 1144 1145 if (userAction == BTN_UP) 1146 { 1147 currState = STATE_MENU_LCD_MODE; 1148 previousMenu = 12; 1149 stateChange = true; 1150 // restore menu item 1151 drawSettingsMenuTimeSet(); 1152 // highlight new menu item 1153 drawSettingsMenuLcdMode(); 1154 } 1155 1156 if (userAction == BTN_DOWN) 1157 { 1158 // restore previous menu item 1159 currState = STATE_MENU_DATE; 1160 previousMenu = 12; 1161 stateChange = true; 1162 // restore menu item 1163 drawSettingsMenuTimeSet(); 1164 // highlight new menu item 1165 drawSettingsMenuDateSet(); 1166 } 1167 1168 1169 break; 1170 1171 case STATE_MENU_SET_TIME_HOUR: //--------------------{ 14 }--{ MENU_SET_TIME_HOUR }---------------------- 1172 1173 if (userAction == BTN_SELECT) 1174 { 1175 1176 // remove red background 1177 tft.setCursor(1, 86); 1178 tft.setTextColor(YELLOW, BLACK); 1179 TMPhour < 10 ? (tft << " " << TMPhour) : tft << TMPhour; 1180 // red background minutes 1181 tft.setCursor(19, 86); 1182 tft.setTextColor(WHITE, RED); 1183 TMPminute < 10 ? (tft << "0" << TMPminute) : tft << TMPminute; 1184 1185 currState = STATE_MENU_SET_TIME_MINUTES; 1186 previousMenu = 13; 1187 stateChange = true; 1188 1189 } 1190 1191 if (userAction == BTN_UP) 1192 { 1193 TMPhour += 1; 1194 if (TMPhour > 23) TMPhour = 0; 1195 if (TMPhour < 0) TMPhour = 23; 1196 1197 tft.setCursor(1, 86); 1198 TMPhour < 10 ? (tft << " " << TMPhour) : tft << TMPhour; 1199 1200 } 1201 1202 if (userAction == BTN_DOWN) 1203 { 1204 TMPhour -= 1; 1205 if (TMPhour > 23) TMPhour = 0; 1206 if (TMPhour < 0) TMPhour = 23; 1207 1208 tft.setCursor(1, 86); 1209 TMPhour < 10 ? (tft << " " << TMPhour) : tft << TMPhour; 1210 } 1211 1212 1213 break; 1214 1215 case STATE_MENU_SET_TIME_MINUTES: //--------------------{ 15 }--{ MENU_SET_TIME_MINUTES }---------------------- 1216 1217 if (userAction == BTN_SELECT) 1218 { 1219 // remove red background 1220 tft.setCursor(19, 86); 1221 tft.setTextColor(YELLOW, BLACK); 1222 TMPminute < 10 ? (tft << "0" << TMPminute) : tft << TMPminute; 1223 1224 needToSaveTime = true; 1225 1226 currState = STATE_MENU_TIME; 1227 previousMenu = 14; 1228 stateChange = true; 1229 } 1230 1231 if (userAction == BTN_UP) 1232 { 1233 TMPminute += 1; 1234 if (TMPminute > 59) TMPminute = 0; 1235 if (TMPminute < 0) TMPminute = 59; 1236 1237 tft.setCursor(19, 86); 1238 TMPminute < 10 ? (tft << "0" << TMPminute) : tft << TMPminute; 1239 1240 } 1241 1242 if (userAction == BTN_DOWN) 1243 { 1244 TMPminute -= 1; 1245 if (TMPminute > 59) TMPminute = 0; 1246 if (TMPminute < 0) TMPminute = 59; 1247 1248 tft.setCursor(19, 86); 1249 TMPminute < 10 ? (tft << "0" << TMPminute) : tft << TMPminute; 1250 } 1251 1252 break; 1253 1254 case STATE_MENU_DATE: //--------------------{ 16 }--{ MENU_DATE }---------------------- 1255 1256 1257 if (userAction == BTN_SELECT) 1258 { 1259 timeDateToTemporaryMem(); 1260 1261 tft.setCursor(1, 108); 1262 tft.setTextColor(WHITE, RED); 1263 TMPday < 10 ? (tft << "0" << TMPday) : tft << TMPday; 1264 1265 currState = STATE_MENU_SET_DAY; 1266 stateChange = true; 1267 } 1268 1269 if (userAction == BTN_UP) 1270 { 1271 currState = STATE_MENU_TIME; 1272 stateChange = true; 1273 // restore menu item 1274 drawSettingsMenuDateSet(); 1275 // highlight new menu item 1276 drawSettingsMenuTimeSet(); 1277 } 1278 1279 if (userAction == BTN_DOWN) 1280 { 1281 // set new state 1282 currState = STATE_MENU_BAROGRAPH; 1283 previousMenu = 15; 1284 stateChange = true; 1285 // restore menu item 1286 drawSettingsMenuDateSet(); 1287 // highlight new menu item 1288 drawSettingsMenuBarograph(); 1289 } 1290 1291 break; 1292 1293 case STATE_MENU_SET_DAY: //--------------------{ 17 }--{ STATE SET_DAY }---------------------- 1294 1295 if (userAction == BTN_SELECT) 1296 { 1297 // goto next item, first remove red background 1298 tft.setCursor(1, 108); 1299 tft.setTextColor(YELLOW, BLACK); 1300 TMPday < 10 ? (tft << "0" << TMPday) : tft << TMPday; 1301 // set red background month 1302 tft.setCursor(19, 108); 1303 tft.setTextColor(WHITE, RED); 1304 TMPmonth < 10 ? (tft << "0" << TMPmonth) : tft << TMPmonth; 1305 1306 currState = STATE_MENU_SET_MONTH; 1307 previousMenu = 17; 1308 stateChange = true; 1309 } 1310 1311 if (userAction == BTN_UP) 1312 { 1313 TMPday += 1; 1314 if (TMPday > 31) TMPday = 1; 1315 if (TMPday < 1) TMPday = 31; 1316 1317 tft.setCursor(1, 108); 1318 TMPday < 10 ? (tft << "0" << TMPday) : tft << TMPday; 1319 1320 } 1321 1322 if (userAction == BTN_DOWN) 1323 { 1324 TMPday -= 1; 1325 if (TMPday > 31) TMPday = 1; 1326 if (TMPday < 1) TMPday = 31; 1327 1328 tft.setCursor(1, 108); 1329 TMPday < 10 ? (tft << "0" << TMPday) : tft << TMPday; 1330 } 1331 1332 1333 break; 1334 1335 case STATE_MENU_SET_MONTH: //--------------------{ 18 }--{ STATE SET_MONTH }---------------------- 1336 1337 if (userAction == BTN_SELECT) 1338 { 1339 // goto next item, first remove red background 1340 tft.setCursor(19, 108); 1341 tft.setTextColor(YELLOW, BLACK); 1342 TMPmonth < 10 ? (tft << "0" << TMPmonth) : tft << TMPmonth; 1343 // set red background year 1344 tft.setCursor(37, 108); 1345 tft.setTextColor(WHITE, RED); 1346 TMPyear < 10 ? (tft << "200" << TMPyear) : tft << "20" << TMPyear; 1347 1348 currState = STATE_MENU_SET_YEAR; 1349 previousMenu = 18; 1350 stateChange = true; 1351 } 1352 1353 if (userAction == BTN_UP) 1354 { 1355 TMPmonth += 1; 1356 if (TMPmonth > 12) TMPmonth = 1; 1357 if (TMPmonth < 1) TMPmonth = 12; 1358 1359 tft.setCursor(19, 108); 1360 TMPmonth < 10 ? (tft << "0" << TMPmonth) : tft << TMPmonth; 1361 1362 } 1363 1364 if (userAction == BTN_DOWN) 1365 { 1366 TMPmonth -= 1; 1367 if (TMPmonth > 12) TMPmonth = 1; 1368 if (TMPmonth < 1) TMPmonth = 12; 1369 1370 tft.setCursor(19, 108); 1371 TMPmonth < 10 ? (tft << "0" << TMPmonth) : tft << TMPmonth; 1372 } 1373 1374 1375 1376 1377 break; 1378 1379 case STATE_MENU_SET_YEAR: //--------------------{ 19 }--{ STATE SET_YEAR }---------------------- 1380 1381 if (userAction == BTN_SELECT) 1382 { 1383 // goto next item, first remove red background 1384 tft.setCursor(37, 108); 1385 tft.setTextColor(YELLOW, BLACK); 1386 TMPyear < 10 ? (tft << "200" << TMPyear) : tft << "20" << TMPyear; 1387 1388 needToSaveTime = true; 1389 1390 currState = STATE_MENU_DATE; 1391 stateChange = true; 1392 } 1393 1394 if (userAction == BTN_UP) 1395 { 1396 TMPyear += 1; 1397 if (TMPyear > 99) TMPyear = 0; 1398 if (TMPyear < 0) TMPyear = 99; 1399 1400 tft.setCursor(49, 108); 1401 TMPyear < 10 ? (tft << "0" << TMPyear) : tft << TMPyear; 1402 1403 } 1404 1405 if (userAction == BTN_DOWN) 1406 { 1407 TMPyear -= 1; 1408 if (TMPyear > 99) TMPyear = 0; 1409 if (TMPyear < 0) TMPyear = 99; 1410 1411 tft.setCursor(49, 108); 1412 TMPyear < 10 ? (tft << "0" << TMPyear) : tft << TMPyear; 1413 } 1414 1415 break; 1416 1417 case STATE_MENU_BAROGRAPH: 1418 1419 if (userAction == BTN_SELECT) 1420 { 1421 // set red background 1422 tft.setCursor(135, 95); 1423 tft.setTextColor(WHITE, RED); 1424 1425 currState = STATE_MENU_SET_PRESSURE_CORRECTION; 1426 stateChange = true; 1427 } 1428 1429 if (userAction == BTN_UP) 1430 { 1431 currState = STATE_MENU_DATE; 1432 stateChange = true; 1433 // restore menu item 1434 drawSettingsMenuBarograph(); 1435 // highlight new menu item 1436 drawSettingsMenuDateSet(); 1437 } 1438 1439 if (userAction == BTN_DOWN) 1440 { 1441 // set new state 1442 currState = STATE_MENU_ALARM_TIME; 1443 stateChange = true; 1444 // restore menu item 1445 drawSettingsMenuBarograph(); 1446 // highlight new menu item 1447 drawSettingsMenuTimeSet(); 1448 } 1449 1450 1451 break; 1452 1453 case STATE_MENU_SET_SEA_LEVEL_PRESSURE: 1454 1455 break; 1456 1457 case STATE_MENU_SET_PRESSURE_CORRECTION: 1458 1459 if (userAction == BTN_SELECT) 1460 { 1461 // goto next item, first remove red background 1462 tft.setCursor(135, 95); 1463 tft.setTextColor(YELLOW, BLACK); 1464 1465 currState = STATE_MENU_ALARM_TIME; 1466 stateChange = true; 1467 } 1468 1469 if (userAction == BTN_UP) 1470 { 1471 pressureCorrection += 1; 1472 1473 tft.setCursor(135, 95); 1474 tft << pressureCorrection; 1475 1476 } 1477 1478 if (userAction == BTN_DOWN) 1479 { 1480 pressureCorrection -= 1; 1481 1482 tft.setCursor(135, 95); 1483 tft << pressureCorrection; 1484 } 1485 1486 break; 1487 1488 } 1489} 1490 1491 1492/*************************************************************************************************************************************************** 1493 1494 ##### ###### ## ###### ####### ## ## ## #### ## ## ###### ## ## ####### 1495 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ### ## ## 1496 ## ## #### ## ## ### ### #### ## ## ## ## ### ## ## 1497 ##### ## ## # ## ##### ## # ## ## # ## ####### ## ## # ## ##### 1498 ## ## ###### ## ## ## # ## ###### ## ## ## ## ## # ## ## 1499 ## ## ## ## # ## ## ## ## ## # ## ## ## ## ## ## ### ## 1500 ##### ## ### ## ## ####### ## ## ### ## #### ## ## ###### ## ## ####### 1501 1502****************************************************************************************************************************************************/ 1503void executeState() 1504{ 1505 // Uses the current state to decide what to process 1506 switch (currState) 1507 { 1508 case STATE_MAIN: //---------------------{ 0 }--{ STATE MAIN }---------------------------- 1509 1510 // update LED ring = seconds display every second after RTC SQW interrupt is detected 1511 displaySeconds(); 1512 1513 // update 7 segment displays time and date 1514 if ( previousMinute != minute() || startup == true ) 1515 { 1516 previousMinute = minute(); 1517 1518 checkForDstChange(); 1519 displayTime(); 1520 displayDate(); 1521 } 1522 1523 // update Arduino time every hour and 30 seconds 1524 if ( previousHour != hour() && second() == 30 ) 1525 { 1526 previousHour = hour(); 1527 readRTC(); 1528 setTime(TMPhour, TMPminute, TMPsecond, TMPday, TMPmonth, TMPyear); 1529 } 1530 1531 // reset temperature and humidity memory at midnight 1532 if (hour() == 00 && minute() == 00 && second() == 00 || startup == true) 1533 { 1534 minTemp = maxTemp = tempCelcius; 1535 minTempHour = minTempMinute = maxTempHour = maxTempMinute = 0; 1536 minHumidity = maxHumidity = humidity; 1537 minHumidityHour = minHumidityMinute = maxHumidityHour = maxHumidityMinute = 0; 1538 } 1539 1540 // update pressure data array and trend value every 'readWeatherdataInterval' 1541 if ( ( minute() % readWeatherdataInterval == 0 && second() == 5 ) ) 1542 { 1543 // read pressure data 1544 readPressure(); 1545 // store new pressure data in array 1546 storePressure(); 1547 } 1548 1549 // request temperature with DS18B20 sensor one second before reading it because of sensor delay of 750ms at 12 bit resolution 1550 if ( second() == 14 || second() == 29 || second() == 44 || second() == 59 ) 1551 { 1552 requestTemperature(); 1553 } 1554 1555 // update several values after startup and every 15 seconds 1556 if ( second() % 15 == 0 || startup == true || stateChange == true) 1557 { 1558 readTemperature(); 1559 readHumidity(); 1560 readPressure(); 1561 calculateBaroTrend(); 1562 } 1563 1564 1565 // update TFT screen 1566 tftMain(); 1567 1568 1569 startup = false; 1570 stateChange = false; 1571 ledRingModeIsChanged = false; 1572 1573 break; 1574 1575 case STATE_TEMP_DISPLAY: //---------------------{ 1 }--{ STATE TEMP DISPLAY }-------------------- 1576 1577 // update LED ring = seconds display every second after RTC SQW interrupt is detected 1578 displaySeconds(); 1579 1580 // update 7 segment display time and date 1581 if ( previousMinute != minute() ) 1582 { 1583 previousMinute = minute(); 1584 1585 checkForDstChange(); 1586 displayTime(); 1587 displayDate(); 1588 } 1589 1590 // update Arduino time every hour and 30 seconds 1591 if ( previousHour != hour() && second() == 30 ) 1592 { 1593 previousHour = hour(); 1594 readRTC(); 1595 setTime(TMPhour, TMPminute, TMPsecond, TMPday, TMPmonth, TMPyear); 1596 } 1597 1598 // reset temperature and humidity memory at midnight 1599 if (hour() == 00 && minute() == 00 && second() == 00 ) 1600 { 1601 minTemp = maxTemp = tempCelcius; 1602 minTempHour = minTempMinute = maxTempHour = maxTempMinute = 0; 1603 minHumidity = maxHumidity = humidity; 1604 minHumidityHour = minHumidityMinute = maxHumidityHour = maxHumidityMinute = 0; 1605 } 1606 1607 // update pressure reading every 'readWeatherdataInterval' 1608 if ( ( minute() % readWeatherdataInterval == 0 && second() == 5 ) ) 1609 { 1610 // read pressure data 1611 readPressure(); 1612 // store new pressure data in array 1613 storePressure(); 1614 } 1615 1616 // request temperature with DS18B20 sensor one second before reading it because of sensor delay of 750ms at 12 bit resolution 1617 if ( second() == 14 || second() == 29 || second() == 44 || second() == 59 ) 1618 { 1619 requestTemperature(); 1620 } 1621 1622 // update lcd screen after startup and every 15 seconds 1623 if ( second() % 15 == 0 || stateChange == true) 1624 { 1625 readTemperature(); 1626 readHumidity(); 1627 calculateClimateComfort(); 1628 } 1629 1630 // update tft screen 1631 tftTemperature(); 1632 1633 stateChange = false; 1634 temperatureMemoryReset = false; 1635 ledRingModeIsChanged = false; 1636 break; 1637 1638 case STATE_HUMIDITY_DISPLAY: //---------------------{ 2 }--{ STATE HUMIDITY DISPLAY }-------------------- 1639 1640 // update LED ring = seconds display every second after RTC SQW interrupt is detected 1641 displaySeconds(); 1642 1643 // update 7 segment display time and date 1644 if ( previousMinute != minute() ) 1645 { 1646 previousMinute = minute(); 1647 1648 checkForDstChange(); 1649 displayTime(); 1650 displayDate(); 1651 } 1652 1653 // update Arduino time every hour and 30 seconds 1654 if ( previousHour != hour() && second() == 30 ) 1655 { 1656 previousHour = hour(); 1657 readRTC(); 1658 setTime(TMPhour, TMPminute, TMPsecond, TMPday, TMPmonth, TMPyear); 1659 } 1660 1661 // reset temperature and humidity memory at midnight 1662 if (hour() == 00 && minute() == 00 && second() == 00 ) 1663 { 1664 minTemp = maxTemp = tempCelcius; 1665 minTempHour = minTempMinute = maxTempHour = maxTempMinute = 0; 1666 minHumidity = maxHumidity = humidity; 1667 minHumidityHour = minHumidityMinute = maxHumidityHour = maxHumidityMinute = 0; 1668 } 1669 1670 // update pressure reading every 'readWeatherdataInterval' 1671 if ( ( minute() % readWeatherdataInterval == 0 && second() == 5 ) ) 1672 { 1673 // read pressure data 1674 readPressure(); 1675 // store new pressure data in array 1676 storePressure(); 1677 } 1678 1679 // request temperature with DS18B20 sensor one second before reading it because of sensor delay of 750ms at 12 bit resolution 1680 if ( second() == 14 || second() == 29 || second() == 44 || second() == 59 ) 1681 { 1682 requestTemperature(); 1683 } 1684 1685 // update lcd screen after startup and every 15 seconds 1686 if ( second() % 15 == 0 || stateChange == true) 1687 { 1688 readTemperature(); 1689 readHumidity(); 1690 calculateClimateComfort(); 1691 } 1692 1693 // update tft screen 1694 tftHumidity(); 1695 1696 stateChange = false; 1697 humidityMemoryReset = false; 1698 ledRingModeIsChanged = false; 1699 break; 1700 1701 case STATE_TIME_DETAIL: //---------------------{ 2 }--{ STATE TIME DETAIL }--------------------- 1702 1703 // update LED ring = seconds display every second after RTC SQW interrupt is detected 1704 displaySeconds(); 1705 1706 // update 7 segment display time and date 1707 if ( previousMinute != minute() ) 1708 { 1709 previousMinute = minute(); 1710 1711 checkForDstChange(); 1712 displayTime(); 1713 displayDate(); 1714 } 1715 1716 // update Arduino time every hour and 30 seconds 1717 if ( previousHour != hour() && second() == 30 ) 1718 { 1719 previousHour = hour(); 1720 readRTC(); 1721 setTime(TMPhour, TMPminute, TMPsecond, TMPday, TMPmonth, TMPyear); 1722 } 1723 1724 // reset temperature and humidity memory at midnight 1725 if (hour() == 00 && minute() == 00 && second() == 00 ) 1726 { 1727 minTemp = maxTemp = tempCelcius; 1728 minTempHour = minTempMinute = maxTempHour = maxTempMinute = 0; 1729 minHumidity = maxHumidity = humidity; 1730 minHumidityHour = minHumidityMinute = maxHumidityHour = maxHumidityMinute = 0; 1731 } 1732 1733 // set seconds() to zero when MEMORY_RESET is detected 1734 if (setSecondsToZero == true) 1735 { 1736 //transfer time/date info in temporary variables 1737 timeDateToTemporaryMem(); 1738 1739 if (TMPsecond <= 30) 1740 { 1741 maxim.clearDisplay(SECONDSDISPLAY); // clear display 1742 TMPsecond = 0; 1743 setTime(TMPhour, TMPminute, TMPsecond, TMPday, TMPmonth, TMPyear); 1744 writeRTC(); 1745 } 1746 else if (TMPsecond > 30) 1747 { 1748 maxim.clearDisplay(SECONDSDISPLAY); // clear display 1749 TMPsecond = 0; 1750 TMPminute += 1; 1751 setTime(TMPhour, TMPminute, TMPsecond, TMPday, TMPmonth, TMPyear); 1752 writeRTC(); 1753 } 1754 1755 }// if(setSecondsToZero == true) 1756 1757 // update tft display 1758 tftTime(); 1759 1760 setSecondsToZero = false; 1761 stateChange = false; 1762 ledRingModeIsChanged = false; 1763 1764 break; 1765 1766 case STATE_BAROGRAPH: //---------------------{ 3 }--{ STATE BAROGRAPH }----------------------- 1767 1768 if (pressureDataToEEprom == true) 1769 { 1770 pressureDataToEEprom = false; 1771 clearTFT(); 1772 eepromWritePressureData(); 1773 1774 tft.setTextColor(GREEN, BLACK); 1775 tft.drawCentreString("Data is" , 80, 25, 4); 1776 tft.drawCentreString("opgeslagen" , 80, 60, 4); 1777 delay(300); 1778 pressureDataUpdated = true; 1779 1780 } 1781 else if (pressureDataFromEEprom == true) 1782 { 1783 pressureDataFromEEprom = false; 1784 clearTFT(); 1785 eepromReadPressureData(); 1786 1787 tft.setTextColor(GREEN, BLACK); 1788 tft.drawCentreString("Data is" , 80, 25, 4); 1789 tft.drawCentreString("ingelezen" , 80, 60, 4); 1790 delay(300); 1791 pressureDataUpdated = true; 1792 1793 } 1794 1795 1796 // update LED ring = seconds display every second after RTC SQW interrupt is detected 1797 displaySeconds(); 1798 1799 // update 7 segment display time and date 1800 if ( previousMinute != minute() ) 1801 { 1802 previousMinute = minute(); 1803 1804 checkForDstChange(); 1805 displayTime(); 1806 displayDate(); 1807 } 1808 1809 // update Arduino time every hour and 30 seconds 1810 if ( previousHour != hour() && second() == 30 ) 1811 { 1812 previousHour = hour(); 1813 readRTC(); 1814 setTime(TMPhour, TMPminute, TMPsecond, TMPday, TMPmonth, TMPyear); 1815 } 1816 1817 // reset temperature and humidity memory at midnight 1818 if (hour() == 00 && minute() == 00 && second() == 00 ) 1819 { 1820 minTemp = maxTemp = tempCelcius; 1821 minTempHour = minTempMinute = maxTempHour = maxTempMinute = 0; 1822 minHumidity = maxHumidity = humidity; 1823 minHumidityHour = minHumidityMinute = maxHumidityHour = maxHumidityMinute = 0; 1824 } 1825 1826 // update pressure data array and trend value every 'readWeatherdataInterval' 1827 if ( ( minute() % readWeatherdataInterval == 0 && second() == 5 ) ) 1828 { 1829 // read pressure data 1830 readPressure(); 1831 // store new pressure data in array 1832 storePressure(); 1833 } 1834 1835 // display or refresh tft screen only when pressure data is updated or at State change 1836 if (pressureDataUpdated == true || stateChange == true) 1837 { 1838 tftBarograph(); 1839 } 1840 1841 stateChange = false; 1842 pressureDataUpdated = false; 1843 ledRingModeIsChanged = false; 1844 1845 break; 1846 1847 case STATE_BAROGRAPH_TREND: //---------------------{ 4 }--{ STATE BAROGRAPH TREND }----------------- 1848 1849 // update LED ring = seconds display every second after RTC SQW interrupt is detected 1850 displaySeconds(); 1851 1852 // update 7 segment display time and date 1853 if ( previousMinute != minute() ) 1854 { 1855 previousMinute = minute(); 1856 1857 checkForDstChange(); 1858 displayTime(); 1859 displayDate(); 1860 } 1861 1862 // update Arduino time every hour and 30 seconds 1863 if ( previousHour != hour() && second() == 30 ) 1864 { 1865 previousHour = hour(); 1866 readRTC(); 1867 setTime(TMPhour, TMPminute, TMPsecond, TMPday, TMPmonth, TMPyear); 1868 } 1869 1870 // reset temperature and humidity memory at midnight 1871 if (hour() == 00 && minute() == 00 && second() == 00 ) 1872 { 1873 minTemp = maxTemp = tempCelcius; 1874 minTempHour = minTempMinute = maxTempHour = maxTempMinute = 0; 1875 minHumidity = maxHumidity = humidity; 1876 minHumidityHour = minHumidityMinute = maxHumidityHour = maxHumidityMinute = 0; 1877 } 1878 1879 // update pressure data array and trend value every 'readWeatherdataInterval' 1880 if ( ( minute() % readWeatherdataInterval == 0 && second() == 5 ) ) 1881 { 1882 // read pressure data 1883 readPressure(); 1884 // store new pressure data in array 1885 storePressure(); 1886 } 1887 1888 // display or refresh tft screen only when pressure data is updated or at State change 1889 if (pressureDataUpdated == true || stateChange == true) 1890 { 1891 tftBaroTrend(); 1892 } 1893 1894 stateChange = false; 1895 pressureDataUpdated = false; 1896 ledRingModeIsChanged = false; 1897 1898 break; 1899 1900 case STATE_MENU_ALARM_TIME: 1901 1902 break; 1903 1904 case STATE_MENU_SET_ALARM_HOUR: 1905 1906 break; 1907 1908 case STATE_MENU_SET_ALARM_MINUTES: 1909 1910 break; 1911 1912 case STATE_MENU_SECONDS_RING: 1913 1914 break; 1915 1916 case STATE_MENU_SET_SECONDS_RING_MODE: 1917 1918 break; 1919 1920 case STATE_MENU_LCD_MODE: 1921 1922 break; 1923 1924 case STATE_MENU_SET_LCD_MODE: 1925 1926 break; 1927 1928 case STATE_MENU_TIME: 1929 1930 // check if settings has changed 1931 if (needToSaveTime == true) 1932 { 1933 maxim.clearDisplay(SECONDSDISPLAY); 1934 setTime(TMPhour, TMPminute, 0, TMPday, TMPmonth, TMPyear); 1935 writeRTC(); 1936 needToSaveTime = false; 1937 } 1938 1939 break; 1940 1941 case STATE_MENU_SET_TIME_HOUR: 1942 1943 break; 1944 1945 case STATE_MENU_SET_TIME_MINUTES: 1946 1947 break; 1948 1949 case STATE_MENU_DATE: 1950 1951 // check if settings has changed 1952 if (needToSaveTime == true) 1953 { 1954 maxim.clearDisplay(SECONDSDISPLAY); // clear display 1955 setTime(TMPhour, TMPminute, 0, TMPday, TMPmonth, TMPyear); 1956 writeRTC(); 1957 needToSaveTime = false; 1958 } 1959 1960 break; 1961 1962 case STATE_MENU_SET_DAY: 1963 1964 break; 1965 1966 case STATE_MENU_SET_MONTH: 1967 1968 break; 1969 1970 case STATE_MENU_SET_YEAR: 1971 1972 break; 1973 1974 case STATE_MENU_BAROGRAPH: 1975 1976 break; 1977 1978 case STATE_MENU_SET_SEA_LEVEL_PRESSURE: 1979 1980 break; 1981 1982 case STATE_MENU_SET_PRESSURE_CORRECTION: 1983 1984 break; 1985 1986 } 1987} 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014/*************************************************************************************************************************************************** 2015 2016 ###### ####### ###### ## ## ## ###### ## ## 2017 ## ## ## ## ## ## ## ### ## 2018 ## ## ## ### ### #### ## ### ## 2019 ## ##### ## ## # ## ## # ## ## # ## 2020 ## ## ## ## # ## ###### ## ## # ## 2021 ## ## ## ## ## ## # ## ## ### 2022 ## ## ## ## ## ### ## ###### ## ## 2023 2024****************************************************************************************************************************************************/ 2025void tftMain() 2026{ 2027 // display standard text 2028 if (stateChange == true || startup == true) 2029 { 2030 tft.setTextColor(CYAN, BLACK); 2031 tft.setTextSize(1); 2032 tft.drawString("Luchtdruk" , 5, 0, 2); 2033 tft.drawRightString("mBar" , 155, 0, 2); 2034 } 2035 2036 // refresh TFT display elements at different intervals due to slow TFT 2037 2038 // display current pressure 2039 if ( second() == 1 || second() == 16 || second() == 31 || second() == 46 || startup == true || stateChange == true ) 2040 { 2041 tft.setTextColor(WHITE, BLACK); 2042 if (pressure / 10 < 1000) 2043 { 2044 tft.drawString(" ", 3, 22, 6); 2045 tft.drawFloat((float)pressure / 10, 1, 30, 26, 6); 2046 } 2047 else 2048 { 2049 tft.drawFloat((float)pressure / 10, 1, 3, 26, 6); 2050 } 2051 2052 }// if second() 2053 2054 2055 // display pressure trend 2056 if ( second() == 2 || second() == 17 || second() == 32 || second() == 47 || startup == true || stateChange == true ) 2057 { 2058 2059 // draw barometric trend graphics 2060 tft.setTextColor(WHITE, BLACK); 2061 tft.drawString("Trend", 105, 97, 2); 2062 drawTrendIndicators(); 2063 2064 // trand value not available yet (only after 3 hours) 2065 if (baroTrend == NA) 2066 { 2067 tft.setTextColor(DGRAY, BLACK); 2068 tft.drawString("N/A", 38, 95, 4); 2069 } 2070 2071 // trend value is available so draw trend value 2072 if (baroTrend != NA) 2073 { 2074 if (baroTrendValue < 0) 2075 { 2076 //draw MINUS sign 2077 drawSign(8, 99, 0); 2078 // draw value 2079 char tmp[6]; 2080 sprintf(tmp, "%u.%u", abs(baroTrendValue / 10), abs(baroTrendValue % 10) ); 2081 tft.setTextColor(RED, BLACK); 2082 tft.drawString( tmp, 28, 87, 6); 2083 } 2084 else if (baroTrendValue > 0) 2085 { 2086 //draw PLUS sign 2087 drawSign(8, 99, 1); 2088 // draw value 2089 char tmp[6]; 2090 sprintf(tmp, "%u.%u", abs(baroTrendValue / 10), abs(baroTrendValue % 10) ); 2091 tft.setTextColor(GREEN, BLACK); 2092 tft.drawString( tmp, 28, 87, 6); 2093 } 2094 else if (baroTrendValue == 0) 2095 { 2096 //CLEAR sign 2097 drawSign(8, 99, 9); 2098 // draw value 2099 char tmp[6]; 2100 sprintf(tmp, "%u.%u", abs(baroTrendValue / 10), abs(baroTrendValue % 10) ); 2101 tft.setTextColor(YELLOW, BLACK); 2102 tft.drawString( tmp, 28, 87, 6); 2103 } 2104 2105 } // if(baroTrend != NA) 2106 2107 }// if 2108 2109}// tftMain() 2110 2111/*************************************************************************************************************************************************** 2112 2113 ###### ####### ###### ###### ####### ## ## ###### ####### ###### ## ###### ## ## ###### ####### 2114 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 2115 ## ## ## ## ## ### ### ## ## ## ## ## #### ## ## ## ## ## ## 2116 ## ##### ## ## ##### ## # ## ###### ##### ###### ## # ## ## ## ###### ##### 2117 ## ## ## ## ## ## # ## ## ## ## ## ###### ## ## ## ## ## ## 2118 ## ## ## ## ## ## ## ## ## ## ## ## # ## ## ## ## ## ## 2119 ## ## ## ## ####### ## ## ## ####### ## ## ### ## ## ##### ## ## ####### 2120 2121****************************************************************************************************************************************************/ 2122void tftTemperature() 2123{ 2124 // display standard text 2125 if (stateChange == true) 2126 { 2127 tft.setTextSize(1); 2128 tft.setTextColor(CYAN, BLACK); 2129 tft.drawString("Temperatuur" , 2, 0, 2); 2130 tft.drawRightString("Celcius" , 157, 0, 2); 2131 tft.setTextColor(WHITE, BLACK); 2132 tft.drawString("o" , 133, 30, 2); 2133 tft.drawString("C" , 140, 42, 4); 2134 2135 // draw UP arrow for max temp value 2136 //tft.fillTriangle(0, 98, 16, 98, 8, 83, GREEN); 2137 tft.fillTriangle(0, 98, 16, 98, 8, 88, GREEN); 2138 tft.drawCircle(74, 87, 2, GREEN); 2139 tft.setTextColor(GREEN, BLACK); 2140 tft.drawString("C" , 78, 86, 2); 2141 2142 // draw DOWN arrow for min temp value 2143 //tft.fillTriangle(0, 111, 16, 111, 8, 126, RED); 2144 tft.fillTriangle(0, 111, 16, 111, 8, 121, RED); 2145 tft.drawCircle(74, 116, 2, RED); 2146 tft.setTextColor(RED, BLACK); 2147 tft.drawString("C" , 78, 115, 2); 2148 } 2149 2150 //@2 2151 2152 // display current temperature value 2153 if ( second() == 1 || second() == 16 || second() == 31 || second() == 46 || stateChange == true ) 2154 { 2155 // draw current temperature value 2156 char tmpCurr[6]; 2157 sprintf(tmpCurr, "%u.%u", (tempCelcius / 10), (tempCelcius % 10) ); 2158 tft.setTextColor(WHITE, BLACK); 2159 tft.drawRightString( tmpCurr, 127, 26, 6); 2160 } 2161 2162 // display min/max temperature values 2163 if ( second() == 2 || second() == 17 || second() == 32 || second() == 47 || stateChange == true || temperatureMemoryReset == true) 2164 { 2165 // draw Max temperature value 2166 char tmpMax[6]; 2167 sprintf(tmpMax, "%u.%u", (maxTemp / 10), (maxTemp % 10) ); 2168 tft.setTextColor(GREEN, BLACK); 2169 tft.drawRightString( tmpMax, 70, 80, 4); 2170 2171 // draw Max temperature time 2172 char tmpMaxT[6]; 2173 sprintf(tmpMaxT, "%02u:%02u", maxTempHour, maxTempMinute ); 2174 tft.setTextColor(GREEN, BLACK); 2175 tft.drawRightString( tmpMaxT, 159, 80, 4); 2176 } 2177 2178 // display min/max temperature values 2179 if ( second() == 3 || second() == 18 || second() == 33 || second() == 48 || stateChange == true || temperatureMemoryReset == true) 2180 { 2181 // draw Min temperature value 2182 char tmpMin[6]; 2183 sprintf(tmpMin, "%u.%u", (minTemp / 10), (minTemp % 10) ); 2184 tft.setTextColor(RED, BLACK); 2185 tft.drawRightString( tmpMin, 70, 109, 4); 2186 2187 // draw Min temperature time 2188 char tmpMinT[6]; 2189 sprintf(tmpMinT, "%02u:%02u", minTempHour, minTempMinute ); 2190 tft.setTextColor(RED, BLACK); 2191 tft.drawRightString( tmpMinT, 159, 109, 4); 2192 } 2193} 2194 2195/*************************************************************************************************************************************************** 2196 2197 2198 2199 TFT HUMIDITY 2200 2201 2202 2203****************************************************************************************************************************************************/ 2204void tftHumidity() 2205{ 2206 // display standard text 2207 if (stateChange == true) 2208 { 2209 tft.setTextSize(1); 2210 tft.setTextColor(CYAN, BLACK); 2211 tft.drawString("Rel. luchtvochtigheid" , 2, 0, 2); 2212 tft.drawRightString("%" , 157, 0, 2); 2213 tft.setTextColor(WHITE, BLACK); 2214 tft.drawString("%" , 137, 42, 4); 2215 2216 // draw UP arrow for max temp value 2217 //tft.fillTriangle(0, 98, 16, 98, 8, 83, GREEN); 2218 tft.fillTriangle(0, 98, 16, 98, 8, 88, GREEN); 2219 tft.setTextColor(GREEN, BLACK); 2220 tft.drawString("%" , 76, 86, 2); 2221 2222 // draw DOWN arrow for min temp value 2223 //tft.fillTriangle(0, 111, 16, 111, 8, 126, RED); 2224 tft.fillTriangle(0, 111, 16, 111, 8, 121, RED); 2225 tft.setTextColor(RED, BLACK); 2226 tft.drawString("%" , 76, 115, 2); 2227 } 2228 2229 // display current humidity value 2230 if ( second() == 1 || second() == 16 || second() == 31 || second() == 46 || stateChange == true ) 2231 { 2232 // draw current humidity value 2233 char tmpCurr[6]; 2234 sprintf(tmpCurr, "%u.%u", (humidity / 10), (humidity % 10) ); 2235 tft.setTextColor(WHITE, BLACK); 2236 tft.drawRightString( tmpCurr, 127, 26, 6); 2237 } 2238 2239 // display max humidity values 2240 if ( second() == 2 || second() == 17 || second() == 32 || second() == 47 || stateChange == true || humidityMemoryReset == true ) 2241 { 2242 // draw Max humidity value 2243 char tmpMax[6]; 2244 sprintf(tmpMax, "%u.%u", (maxHumidity / 10), (maxHumidity % 10) ); 2245 tft.setTextColor(GREEN, BLACK); 2246 tft.drawRightString( tmpMax, 70, 80, 4); 2247 2248 // draw Max humidity time 2249 char tmpMaxT[6]; 2250 sprintf(tmpMaxT, "%02u:%02u", maxHumidityHour, maxHumidityMinute ); 2251 tft.setTextColor(GREEN, BLACK); 2252 tft.drawRightString( tmpMaxT, 159, 80, 4); 2253 } 2254 2255 // display min humidity values 2256 if ( second() == 3 || second() == 18 || second() == 33 || second() == 48 || stateChange == true || humidityMemoryReset == true ) 2257 { 2258 // draw Min humidity value 2259 char tmpMin[6]; 2260 sprintf(tmpMin, "%u.%u", (minHumidity / 10), (minHumidity % 10) ); 2261 tft.setTextColor(RED, BLACK); 2262 tft.drawRightString( tmpMin, 70, 109, 4); 2263 2264 // draw Min humidity time 2265 char tmpMinT[6]; 2266 sprintf(tmpMinT, "%02u:%02u", minHumidityHour, minHumidityMinute ); 2267 tft.setTextColor(RED, BLACK); 2268 tft.drawRightString( tmpMinT, 159, 109, 4); 2269 } 2270 2271 // display comfort indicator 2272 if ( second() == 4 || second() == 19 || second() == 34 || second() == 49 || stateChange == true ) 2273 { 2274 2275 tft.fillCircle(10, 32, 7, LGRAY); 2276 tft.fillCircle(10, 44, 7, LGRAY); 2277 tft.fillCircle(10, 56, 7, LGRAY); 2278 tft.fillRect(3, 32, 15, 23, LGRAY); 2279 tft.fillCircle(10, 32, 5, DGRAY); 2280 tft.fillCircle(10, 44, 5, DGRAY); 2281 tft.fillCircle(10, 56, 5, DGRAY); 2282 2283 2284 if (climateComfort == ccRED) 2285 { 2286 tft.fillCircle(10, 32, 5, RED); 2287 } 2288 else if (climateComfort == ccYELLOW) 2289 { 2290 tft.fillCircle(10, 44, 5, YELLOW); 2291 } 2292 else if (climateComfort == ccGREEN) 2293 { 2294 tft.fillCircle(10, 56, 5, GREEN); 2295 } 2296 } 2297 2298 2299} 2300 2301 2302/*************************************************************************************************************************************************** 2303 2304 ###### ####### ###### ###### ###### ## ## ####### 2305 ## ## ## ## ## ## ## ## 2306 ## ## ## ## ## ### ### ## 2307 ## ##### ## ## ## ## # ## ##### 2308 ## ## ## ## ## ## # ## ## 2309 ## ## ## ## ## ## ## ## 2310 ## ## ## ## ###### ## ## ####### 2311 2312****************************************************************************************************************************************************/ 2313void tftTime() 2314{ 2315 // draw seconds 2316 char tmpS[6]; 2317 sprintf(tmpS, "%02u", second() ); 2318 tft.setTextColor(WHITE, BLACK); 2319 tft.drawRightString( tmpS, 159, 17, 4); 2320 2321 // update only when minutes change 2322 if ( second() == 0 || stateChange == true ) 2323 { 2324 // draw time 2325 tft.setTextSize(1); 2326 char tmpT[6]; 2327 sprintf(tmpT, "%02u:%02u", hour(), minute() ); 2328 tft.setTextColor(WHITE, BLACK); 2329 tft.drawString( tmpT, 0, 0, 6); 2330 } 2331 2332 2333 // update 2334 if (hour() == 00 && minute() == 00 && second() == 00 || stateChange == true) 2335 { 2336 // draw weekday 2337 tft.setTextColor(MAGENTA, BLACK); 2338 tft.drawCentreString(strDOW[weekday()], 79, 48, 4); 2339 2340 // draw date 2341 char tmpD[6]; 2342 sprintf(tmpD, "%u %s %4u", day(), strMonth[month()], year() ); 2343 tft.setTextColor(GREEN, BLACK); 2344 tft.drawCentreString(tmpD, 79, 79, 4); 2345 2346 // display Leap Year 2347 tft.setTextColor(RED, BLACK); 2348 // first calculate if this is a leap year: 2349 calculateLeapYear() == 1 ? tft.drawRightString("S", 159, 79, 4) : tft.drawRightString(" ", 159, 79, 4); 2350 2351 // display DST 2352 tft.setTextColor(YELLOW, BLACK); 2353 daylightSavingTime == true ? tft.drawString("ZT", 0, 109, 4) : tft.drawString("WT", 0, 109, 4); 2354 2355 // display Week number 2356 char tmpW[6]; 2357 sprintf(tmpW, "%s %2u", "Week", dayWeekNumber(year(), month(), day(), weekday()) ); 2358 tft.setTextColor(CYAN, BLACK); 2359 tft.drawRightString(tmpW, 159, 109, 4); 2360 2361 } 2362 2363} 2364 2365/*************************************************************************************************************************************************** 2366 2367 ###### ####### ###### ###### ## ###### ### #### ###### ## ###### ## ## 2368 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 2369 ## ## ## ## ## #### ## ## ## ## ## ## ## #### ## ## ## ## 2370 ## ##### ## ###### ## # ###### ## ## ## ###### ## # ###### ####### 2371 ## ## ## ## ## ###### ## ## ## ## ## ### ## ## ###### ## ## ## 2372 ## ## ## ## ## ## # ## ## ## ## ## ## ## ## ## # ## ## ## 2373 ## ## ## ###### ### ## ## ## ### ##### ## ## ### ## ## ## ## 2374 2375****************************************************************************************************************************************************/ 2376void tftBarograph() 2377{ 2378 clearTFT(); 2379 drawGridLines(); 2380 drawGridTicks(); 2381 drawGridText(); 2382 2383 // determine min/max values of pressure 2384 pressureMin = pressure; 2385 pressureMax = pressure; 2386 2387 for (int pp = 0 ; pp < 130; pp++) 2388 { 2389 // pressureMin cannot be zero due to 'zero' array values so check for that and skip those 2390 if (barometerData[pp] != 0 && pressureMin > barometerData[pp]) 2391 { 2392 pressureMin = barometerData[pp]; 2393 } 2394 if (pressureMax < barometerData[pp]) 2395 { 2396 pressureMax = barometerData[pp]; 2397 } 2398 } 2399 2400 // check if range has changed 2401 if ( (pressureMin < 9800 || pressureMax > 10300) ) 2402 { 2403 highScale = true; 2404 } 2405 else 2406 { 2407 highScale = false; 2408 } 2409 2410 // title text 2411 // display current pressure in top of screen 2412 tft.setTextSize(1); 2413 tft.setCursor(1, 2); 2414 tft.setTextColor(YELLOW, BLACK); 2415 tft << "Barograaf"; 2416 2417 // high/low scale indicator 2418 tft.setCursor(154, 2); 2419 tft.setTextColor(CYAN, BLACK); 2420 tft << (highScale == true ? "H" : "L"); 2421 2422 //draw min/max pressure ticks 2423 tft.drawFastVLine( plotLimitH + 1, grid24VstartpositionYaxis, plotRangeV, BLACK); 2424 tft.drawFastVLine( plotLimitH + 2, grid24VstartpositionYaxis, plotRangeV, BLACK); 2425 tft.drawFastVLine( plotLimitH + 3, grid24VstartpositionYaxis, plotRangeV, BLACK); 2426 drawGridTicks(); 2427 int pressureMinTick = map( pressureMin, (highScale == true ? 9500 : 9800), (highScale == true ? 10500 : 10300), 0, 100); 2428 int pressureMaxTick = map( pressureMax, (highScale == true ? 9500 : 9800), (highScale == true ? 10500 : 10300), 0, 100); 2429 tft.drawFastHLine( plotLimitH + 1 , (plotLimitV - pressureMinTick) , 3 , RED); 2430 tft.drawFastHLine( plotLimitH + 1 , (plotLimitV - pressureMaxTick) , 3 , GREEN); 2431 2432 // draw min/max values on top of screen 2433 tft.setCursor(66, 2); 2434 tft.setTextColor(RED, BLACK); 2435 char tmpPMin[8]; 2436 sprintf(tmpPMin, "%u.%u", pressureMin / 10, pressureMin % 10 ); 2437 tft << tmpPMin; 2438 tft.fillTriangle(60, 4, 64, 4, 62, 8, RED); 2439 2440 tft.setCursor(113, 2); 2441 tft.setTextColor(GREEN, BLACK); 2442 char tmpPMax[8]; 2443 sprintf(tmpPMax, "%u.%u", pressureMax / 10, pressureMax % 10 ); 2444 tft << tmpPMax; 2445 tft.fillTriangle(107, 8, 111, 8, 109, 4, GREEN); 2446 2447 // first delete previous line on x asix pos 0 2448 //tft.drawFastVLine( 0 , grid24HstartpositionYaxis , plotRangeV , BLACK); 2449 2450 //plot pressure history on TFT display 2451 for (int pp = 0 ; pp < plotLimitH; pp++) 2452 { 2453 // contrain plotvalue and map it to the available plot area considering high/low scale 2454 plotvalueP = map( barometerData[pp] , (highScale == true ? 9500 : 9800), (highScale == true ? 10500 : 10300), 0, 100); 2455 plotvalueP1 = map( barometerData[pp + 1] , (highScale == true ? 9500 : 9800), (highScale == true ? 10500 : 10300), 0, 100); 2456 2457 // check if next value is smaller than current value, if so, erase plot-line before drawing new one 2458 if ( (pp < plotLimitH - 1) && (plotvalueP1 < plotvalueP) ) 2459 { 2460 tft.drawFastVLine( pp + 1 , (plotLimitV - plotvalueP) , (plotvalueP - plotvalueP1) , BLACK); 2461 } 2462 // plot next line 2463 tft.drawFastVLine( pp , (plotLimitV - plotvalueP) , plotvalueP, BLUE); 2464 }// for(int p=0; p<plotLimitH; p++) 2465 2466 //redraw grid after screen update so grid lines are on top of graph 2467 drawGridLines(); 2468 2469 // draw solid line on Y axis, x pos 0 2470 // tft.drawFastVLine(0,15,100, WHITE); 2471 2472 // draw dividing line between hig and low pressure: 1015 hPa 2473 //int pressureMeanLine = map( 10150, (highScale == true ? 9500 : 9800), (highScale == true ? 10500 : 10300), 0, 100); 2474 //tft.drawFastHLine( 0, (plotLimitV - pressureMeanLine) , plotRangeH , ORANGE); 2475 2476}// void displayPressure24hr() 2477 2478/*************************************************************************************************************************************************** 2479 2480 ###### ####### ###### ###### ## ###### ### ###### ###### ####### ## ## ##### 2481 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ### ## ## ## 2482 ## ## ## ## ## #### ## ## ## ## ## ## ## ## ### ## ## ## 2483 ## ##### ## ###### ## # ###### ## ## ## ###### ##### ## # ## ## ## 2484 ## ## ## ## ## ###### ## ## ## ## ## ## ## ## ## # ## ## ## 2485 ## ## ## ## ## ## # ## ## ## ## ## ## ## ## ## ### ## ## 2486 ## ## ## ###### ### ## ## ## ### ## ## ## ####### ## ## ##### 2487 2488****************************************************************************************************************************************************/ 2489void tftBaroTrend() 2490{ 2491 clearTFT(); 2492 2493 // display current pressure in top of screen 2494 tft.setTextSize(1); 2495 tft.setCursor(1, 2); 2496 tft.setTextColor(YELLOW, BLACK); 2497 tft << "Trend (1 uur gemiddelde)"; 2498 2499 2500 // plot horizontal grid lines on TFT display 2501 for ( q = 0; q <= (130) / 2; q++) 2502 { 2503 tft.drawPixel(q * 2, 15 + (0 * 10), GRIDCOLOR); // +5 line 2504 tft.drawPixel(q * 2, 15 + (1 * 10), GRIDCOLOR); // +4 line 2505 tft.drawPixel(q * 2, 15 + (2 * 10), GRIDCOLOR); // +3 line 2506 tft.drawPixel(q * 2, 15 + (3 * 10), GRIDCOLOR); // +2 line 2507 tft.drawPixel(q * 2, 15 + (4 * 10), GRIDCOLOR); // +1 line 2508 tft.drawFastHLine(0, 15 + (5 * 10), 130, WHITE); // 0 (solid) line 2509 tft.drawPixel(q * 2, 15 + (6 * 10), GRIDCOLOR); // +-1 line 2510 tft.drawPixel(q * 2, 15 + (7 * 10), GRIDCOLOR); // +-2 line 2511 tft.drawPixel(q * 2, 15 + (8 * 10), GRIDCOLOR); // +-3 line 2512 tft.drawPixel(q * 2, 15 + (9 * 10), GRIDCOLOR); // +-4 line 2513 2514 } 2515 // plot vertical grid lines on TFT display 2516 for ( q = 0; q <= (plotLimitV - 10) / 2; q++) 2517 { 2518 tft.drawPixel(10 + (0 * 20), ((15) + (q * 2)), GRIDCOLOR); // -24 line 2519 tft.drawPixel(10 + (1 * 20), ((15) + (q * 2)), GRIDCOLOR); // -20 line 2520 tft.drawPixel(10 + (2 * 20), ((15) + (q * 2)), GRIDCOLOR); // -16 line 2521 tft.drawPixel(10 + (3 * 20), ((15) + (q * 2)), GRIDCOLOR); // -12 line 2522 tft.drawPixel(10 + (4 * 20), ((15) + (q * 2)), GRIDCOLOR); // -8 line 2523 tft.drawPixel(10 + (5 * 20), ((15) + (q * 2)), GRIDCOLOR); // -4 line 2524 } 2525 2526 // X axis solid line 2527 tft.drawFastHLine(0, 115, 130, WHITE); 2528 // 1 hour ticks 2529 for ( q = 0; q <= (130 - 5) / 5; q++) 2530 { 2531 tft.drawPixel(5 + q * 5, 115 + 1, WHITE); 2532 } 2533 // 2 hour H ticks 2534 for ( q = 0; q <= (130 - 10) / 20; q++) 2535 { 2536 tft.drawPixel(10 + q * 20, 115 + 2, WHITE); 2537 tft.drawPixel(10 + q * 20, 115 + 3, WHITE); 2538 } 2539 2540 // Y axis solid line 2541 tft.drawFastVLine(130, 15, 115 - 10, WHITE); 2542 // 5Hpa V ticks 2543 for ( q = 0; q <= (115 - 15) / 10; q++) 2544 { 2545 tft.drawPixel(130 + 1, 15 + (q * 10), WHITE); 2546 } 2547 // 10Hpa Vticks 2548 for ( q = 0; q <= (115 - 15) / 10; q++) 2549 { 2550 tft.drawPixel(130 + 2, 15 + (q * 10), WHITE); 2551 tft.drawPixel(130 + 3, 15 + (q * 10), WHITE); 2552 } 2553 // ZERO line extra long tick 2554 tft.drawFastHLine(131, 15 + (5 * 10), 8, WHITE); // 0 (solid) line 2555 2556 2557 //GRID 2558 2559 // plot grid text lines on TFT display 2560 tft.setTextSize(1); 2561 // draw X text 2562 tft.setTextColor(WHITE, BLACK); 2563 tft.setCursor(5, 121); 2564 tft << "24"; 2565 tft.setCursor(25, 121); 2566 tft << "20"; 2567 tft.setCursor(45, 121); 2568 tft << "16"; 2569 tft.setCursor(65, 121); 2570 tft << "12"; 2571 tft.setCursor(88, 121); 2572 tft << "8"; 2573 tft.setCursor(108, 121); 2574 tft << "4"; 2575 tft.setCursor(128, 121); 2576 tft << "0"; 2577 2578 // draw negative signs before hour text 2579 tft.drawFastHLine(1, 124, 3, WHITE); 2580 tft.drawFastHLine(1 + 20 * 1, 124, 3, WHITE); 2581 tft.drawFastHLine(2 + 20 * 2, 124, 3, WHITE); 2582 tft.drawFastHLine(2 + 20 * 3, 124, 3, WHITE); 2583 tft.drawFastHLine(4 + 20 * 4, 124, 3, WHITE); 2584 tft.drawFastHLine(4 + 20 * 5, 124, 3, WHITE); 2585 2586 // draw Y text 2587 tft.setTextColor(GREEN, BLACK); 2588 tft.setCursor(130 + 7, 15 - 3); 2589 tft << "+5"; 2590 tft.setCursor(130 + 7, (15 - 3) + (1 * 10) ); 2591 tft << "+4"; 2592 tft.setCursor(130 + 7, (15 - 3) + (2 * 10) ); 2593 tft << "+3"; 2594 tft.setCursor(130 + 7, (15 - 3) + (3 * 10) ); 2595 tft << "+2"; 2596 tft.setCursor(130 + 7, (15 - 3) + (4 * 10) ); 2597 tft << "+1"; 2598 2599 tft.setTextColor(WHITE, BLACK); 2600 tft.setCursor(130 + 7, (15 - 3) + (5 * 10) ); 2601 tft << " 0"; 2602 2603 tft.setTextColor(RED, BLACK); 2604 tft.setCursor(130 + 7, (15 - 3) + (6 * 10) ); 2605 tft << "-1"; 2606 tft.setCursor(130 + 7, (15 - 3) + (7 * 10) ); 2607 tft << "-2"; 2608 tft.setCursor(130 + 7, (15 - 3) + (8 * 10) ); 2609 tft << "-3"; 2610 tft.setCursor(130 + 7, (15 - 3) + (9 * 10) ); 2611 tft << "-4"; 2612 tft.setCursor(130 + 7, (15 - 3) + (10 * 10) ); 2613 tft << "-5"; 2614 // draw solid line on Y axis, x pos 0 2615 //tft.drawFastVLine(0,15,100, WHITE); 2616 2617 2618 2619 // draw value on graph 2620 2621 // calculate one-hour average of barometer pressure trend 2622 2623 //step 1: calculate averaged one-hour pressure data 2624 for (int s1 = 129; s1 >= 5; s1--) 2625 { 2626 2627 // only proceed if data of past hour is available 2628 if (barometerData[s1 - 5] != 0) 2629 { 2630 2631 // adding up the last five 12-minute pressure readings 2632 readings = 0; 2633 for (int i = 1; i <= 5; i++) 2634 { 2635 //get pressure value (current value-1), (current value-2) until (current value-5) 2636 readings += barometerData[s1 - i]; 2637 } 2638 2639 // average readings and write one-hour average data in array 2640 pressureHourAvarage[s1] = readings / 5; 2641 2642 }// if(barometerData[s1 - 5] != 0) 2643 else 2644 { 2645 // no data available of past hour so fill array data with zero 2646 pressureHourAvarage[s1] = 0; 2647 }// else 2648 2649 }// for(s1 = 129; s1 = 0; s1—-) 2650 2651 // step 2: calculate one-hour barometer pressure difference 2652 for (int s2 = 129; s2 >= 10; s2--) 2653 { 2654 2655 // only proceed if data of past hour is available 2656 if (pressureHourAvarage[s2 - 5] != 0) 2657 { 2658 pressureHourlyTrend = pressureHourAvarage[s2] - pressureHourAvarage[s2 - 5]; 2659 } 2660 else 2661 { 2662 pressureHourlyTrend = 0; 2663 } 2664 2665 2666 // CODE TO PLOT VALUE ON TFT DISPLAY 2667 2668 // map plotvalue to the available plot area 2669 plotvalueT = map( constrain(pressureHourlyTrend, -50, 50), -50, 50, 0, 100); 2670 //draw pt 2671 tft.drawFastVLine( s2 , (114 - plotvalueT) , 3, ORANGE); 2672 2673 }// for(s2 = 129; s2 >= 5; s2—-) 2674 2675 //redraw grid after screen update 2676 //drawGridLines(); 2677 2678}// void tftBaroTrend() 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732/*************************************************************************************************************************************************** 2733 2734 2735 ####### ## ## ## ## #### ###### ###### ### ## ## ##### 2736 ## ## ## ### ## ## ## ## ## ## ## ### ## ## ## 2737 ## ## ## ### ## ## ## ## ## ## ### ## ## 2738 ##### ## ## ## # ## ## ## ## ## ## ## # ## ##### 2739 ## ## ## ## # ## ## ## ## ## ## ## # ## ## 2740 ## ## ## ## ### ## ## ## ## ## ## ## ### ## ## 2741 ## ##### ## ## #### ## ###### ### ## ## ##### 2742 2743 2744****************************************************************************************************************************************************/ 2745 2746 2747 2748 2749/*************************************************************************************************************************************************** 2750 2751 ##### ###### ##### ###### ## ## ## ## ###### ###### ## ## ####### 2752 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 2753 ## ## ## ## ## ## ## #### #### ## ## ### ### ## 2754 ## ## ## ##### ###### ## ## # ## ## ## ## # ## ##### 2755 ## ## ## ## ## ## ###### ## ## ## ## # ## ## 2756 ## ## ## ## ## ## ## ## # ## ## ## ## ## ## 2757 ##### ###### ##### ## ###### ### ## ## ## ###### ## ## ####### 2758 2759****************************************************************************************************************************************************/ 2760void displayTime() 2761{ 2762 2763 //readRTC(); 2764 //readRtcTemp(); 2765 2766 maxim.setChar(TIMEDISPLAY, 3, ((hour() < 10) ? ' ' : (hour() / 10)), false); 2767 maxim.setChar(TIMEDISPLAY, 2, (hour() % 10), true); 2768 maxim.setChar(TIMEDISPLAY, 1, (minute() / 10), false); 2769 maxim.setChar(TIMEDISPLAY, 0, (minute() % 10), false); 2770 2771 //// Serial << "hour() : " << hour() << "\ \ TMPHour : " << TMPhour << endl; 2772 //// Serial << "minute() : " << minute() << "\ \ TMPMinute : " << TMPminute << endl; 2773 //// Serial << "second() : " << second() << "\ \ TMPSecond : " << TMPsecond << endl; 2774 //// Serial << "weekday() : " << weekday() << "\ \ TMPWeekday : " << TMPweekday << endl; 2775 //// Serial << "day() : " << day() << "\ \ TMPDay : " << TMPday << endl; 2776 //// Serial << "month() : " << month() << "\ \ TMPMonth : " << TMPmonth << endl; 2777 //// Serial << "year() : " << year() << "\ TMPYear : " << TMPyear << endl << endl; 2778 //// Serial << "now() : " << now() << endl << endl; 2779 // 2780 //// Serial << "weekday(now() ) : " << weekday(now()) << endl << endl; 2781 // 2782 //// Serial << "Temperature: " << tempCelcius / 10 << "." << tempCelcius % 10 << endl << endl; 2783 2784} 2785 2786/*************************************************************************************************************************************************** 2787 2788 #### ## ## ####### #### ## ## ####### ### ###### ##### ##### ###### 2789 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 2790 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 2791 ## ####### ##### ## #### ##### ## ## ###### ## ## ##### ## 2792 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 2793 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 2794 #### ## ## ####### #### ## ## ## ### ## ## ##### ##### ## 2795 2796****************************************************************************************************************************************************/ 2797 2798void checkForDstChange() 2799{ 2800 2801 // if the 2802 if (daylightSavingTimeHasChanged == true && hour() == 4) 2803 { 2804 daylightSavingTimeHasChanged = false; 2805 } 2806 2807 // check for change in DST 2808 if (daylightSavingTime != myTZ.locIsDST(now()) && daylightSavingTimeHasChanged == false) 2809 { 2810 //DST has changed! 2811 daylightSavingTime = myTZ.locIsDST(now()); 2812 // time/date info to temporary variables 2813 timeDateToTemporaryMem(); 2814 2815 // from winter- to summertime 2816 if (daylightSavingTime == 1) 2817 { 2818 TMPhour += 1; 2819 daylightSavingTimeHasChanged = true; 2820 } 2821 // from summer- to wintertime 2822 else if (daylightSavingTime == 0) 2823 { 2824 TMPhour -= 1; 2825 daylightSavingTimeHasChanged = true; 2826 } 2827 // update RTC 2828 setTime(TMPhour, TMPminute, TMPsecond, TMPday, TMPmonth, TMPyear); 2829 writeRTC(); 2830 displayTime(); 2831 2832 }// if 2833}// void 2834 2835 2836 2837/*************************************************************************************************************************************************** 2838 2839 ##### ###### ##### ###### ## ## ## ## ##### ####### #### ### ## ## ##### ##### 2840 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ### ## ## ## ## ## 2841 ## ## ## ## ## ## ## #### #### ## ## ## ## ## ### ## ## ## ## 2842 ## ## ## ##### ###### ## ## # ## ##### ##### ## ## ## ## # ## ## ## ##### 2843 ## ## ## ## ## ## ###### ## ## ## ## ## ## ## # ## ## ## ## 2844 ## ## ## ## ## ## ## ## # ## ## ## ## ## ## ## ## ## ### ## ## ## ## 2845 ##### ###### ##### ## ###### ### ## ## ##### ####### #### ### ## ## ##### ##### 2846 2847****************************************************************************************************************************************************/ 2848void displaySeconds() 2849{ 2850 switch (ledRingMode) 2851 { 2852 case 0: //POSITIVE RING 2853 // lit LED's from zero to current second 2854 for (int i = 0; i <= second(); i++) 2855 { 2856 maxim.setLed(SECONDSDISPLAY, i / 8, i % 8, true); 2857 } 2858 2859 // at 60 seconds, reset led's 2860 if ( (second() == 0) || startup == true || ledRingModeIsChanged == true) 2861 { 2862 for (int i = 1; i < 60; i++) 2863 { 2864 maxim.setLed(SECONDSDISPLAY, i / 8, i % 8, false); 2865 } 2866 } 2867 break; 2868 2869 case 1: // NEGATIVE RING 2870 // shut off LED's from current second to zero 'count down' 2871 for (int i = 1; i <= second(); i++) 2872 { 2873 maxim.setLed(SECONDSDISPLAY, i / 8, i % 8, false); 2874 } 2875 2876 // at 60 seconds, reset led's 2877 if ( (second() == 0) || startup == true || ledRingModeIsChanged == true) 2878 { 2879 for (int i = 0; i < 60; i++) 2880 { 2881 maxim.setLed(SECONDSDISPLAY, i / 8, i % 8, true); 2882 } 2883 } 2884 break; 2885 2886 case 2: // Single LED lit 2887 2888 // needed for turning off 'stray' lit led's before the actual 'second() led' is set 2889 second() == 0 ? sec = 60 : sec = second(); 2890 2891 // if mode is changed, first clear the led ring 2892 if (ledRingModeIsChanged == true) 2893 { 2894 for (int i = 0; i <= 59; i++) 2895 { 2896 // turn all LED ring LED's off 2897 maxim.setLed(SECONDSDISPLAY, i / 8, i % 8, false); 2898 } 2899 } 2900 2901 // turn off LED's from zero to current second. 2902 for (int i = 0; i <= sec; i++) 2903 { 2904 maxim.setLed(SECONDSDISPLAY, i / 8, i % 8, false); 2905 } 2906 // turn off one led, to indicate the current second 2907 maxim.setLed(SECONDSDISPLAY, second() / 8, second() % 8, true); 2908 2909 2910 break; 2911 2912 case 3: // Single LED INVERSE 2913 2914 // needed for turning on 'stray' dimmed led's before the actual 'second() led' is set 2915 second() == 0 ? sec = 60 : sec = second(); 2916 2917 // because of change of display mode, 'reset' display 2918 if (ledRingModeIsChanged == true) 2919 { 2920 for ( int i = 0; i <= 59; i++) 2921 { 2922 // turn all LED ring LED's on 2923 maxim.setLed(SECONDSDISPLAY, i / 8, i % 8, true); 2924 } 2925 } 2926 2927 // lit LED's from zero to current second. 2928 for (int i = 0; i <= sec; i++) 2929 { 2930 maxim.setLed(SECONDSDISPLAY, i / 8, i % 8, true); 2931 } 2932 // turn off one led, to indicate the current second 2933 maxim.setLed(SECONDSDISPLAY, second() / 8, second() % 8, false); 2934 2935 break; 2936 }// switch 2937}// void displaySeconds() 2938 2939/*************************************************************************************************************************************************** 2940 2941 ##### ###### ##### ###### ## ## ## ## ##### ## ###### ####### 2942 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 2943 ## ## ## ## ## ## ## #### #### ## ## #### ## ## 2944 ## ## ## ##### ###### ## ## # ## ## ## ## # ## ##### 2945 ## ## ## ## ## ## ###### ## ## ## ###### ## ## 2946 ## ## ## ## ## ## ## ## # ## ## ## ## # ## ## 2947 ##### ###### ##### ## ###### ### ## ## ##### ### ## ## ####### 2948 2949****************************************************************************************************************************************************/ 2950void displayDate() 2951{ 2952 // maxim.setChar(DATEDISPLAY, 7, day() / 10, false); 2953 // maxim.setChar(DATEDISPLAY, 6, day() % 10, false); 2954 // maxim.setChar(DATEDISPLAY, 5, '-', false); 2955 switch (weekday()) 2956 { 2957 case 1: // sunday 2958 // clear display 2959 maxim.setChar(DATEDISPLAY, 7, ' ', false); 2960 maxim.setChar(DATEDISPLAY, 6, ' ', false); 2961 // display 'S' 2962 maxim.setLed(DATEDISPLAY, 7, 1, true); 2963 maxim.setLed(DATEDISPLAY, 7, 3, true); 2964 maxim.setLed(DATEDISPLAY, 7, 4, true); 2965 maxim.setLed(DATEDISPLAY, 7, 6, true); 2966 maxim.setLed(DATEDISPLAY, 7, 7, true); 2967 // display 'u' 2968 maxim.setLed(DATEDISPLAY, 6, 3, true); 2969 maxim.setLed(DATEDISPLAY, 6, 4, true); 2970 maxim.setLed(DATEDISPLAY, 6, 5, true); 2971 // display decimal point 2972 //maxim.setLed(DATEDISPLAY, 6, 0, true); 2973 break; 2974 case 2: // monday 2975 // clear display 2976 maxim.setChar(DATEDISPLAY, 7, ' ', false); 2977 maxim.setChar(DATEDISPLAY, 6, ' ', false); 2978 // display 'n' to mimic 'm' 2979 maxim.setLed(DATEDISPLAY, 7, 3, true); 2980 maxim.setLed(DATEDISPLAY, 7, 5, true); 2981 maxim.setLed(DATEDISPLAY, 7, 7, true); 2982 // display 'o' 2983 maxim.setLed(DATEDISPLAY, 6, 3, true); 2984 maxim.setLed(DATEDISPLAY, 6, 4, true); 2985 maxim.setLed(DATEDISPLAY, 6, 5, true); 2986 maxim.setLed(DATEDISPLAY, 6, 7, true); 2987 // display decimal point 2988 //maxim.setLed(DATEDISPLAY, 6, 0, true); 2989 break; 2990 case 3: // tuesday 2991 // clear display 2992 maxim.setChar(DATEDISPLAY, 7, ' ', false); 2993 maxim.setChar(DATEDISPLAY, 6, ' ', false); 2994 // display 't' 2995 maxim.setLed(DATEDISPLAY, 7, 4, true); 2996 maxim.setLed(DATEDISPLAY, 7, 5, true); 2997 maxim.setLed(DATEDISPLAY, 7, 6, true); 2998 maxim.setLed(DATEDISPLAY, 7, 7, true); 2999 // display 'u' 3000 maxim.setLed(DATEDISPLAY, 6, 3, true); 3001 maxim.setLed(DATEDISPLAY, 6, 4, true); 3002 maxim.setLed(DATEDISPLAY, 6, 5, true); 3003 // display decimal point 3004 //maxim.setLed(DATEDISPLAY, 6, 0, true); 3005 break; 3006 case 4: // wednesday 3007 // clear display 3008 maxim.setChar(DATEDISPLAY, 7, ' ', false); 3009 maxim.setChar(DATEDISPLAY, 6, ' ', false); 3010 // display 'u' to mimic 'w' 3011 maxim.setLed(DATEDISPLAY, 7, 3, true); 3012 maxim.setLed(DATEDISPLAY, 7, 4, true); 3013 maxim.setLed(DATEDISPLAY, 7, 5, true); 3014 // display 'E' 3015 maxim.setLed(DATEDISPLAY, 6, 1, true); 3016 maxim.setLed(DATEDISPLAY, 6, 4, true); 3017 maxim.setLed(DATEDISPLAY, 6, 5, true); 3018 maxim.setLed(DATEDISPLAY, 6, 6, true); 3019 maxim.setLed(DATEDISPLAY, 6, 7, true); 3020 // display decimal point 3021 //maxim.setLed(DATEDISPLAY, 6, 0, true); 3022 break; 3023 case 5: // thursday 3024 // clear display 3025 maxim.setChar(DATEDISPLAY, 7, ' ', false); 3026 maxim.setChar(DATEDISPLAY, 6, ' ', false); 3027 // display 't' 3028 maxim.setLed(DATEDISPLAY, 7, 4, true); 3029 maxim.setLed(DATEDISPLAY, 7, 5, true); 3030 maxim.setLed(DATEDISPLAY, 7, 6, true); 3031 maxim.setLed(DATEDISPLAY, 7, 7, true); 3032 // display 'h' 3033 maxim.setLed(DATEDISPLAY, 6, 3, true); 3034 maxim.setLed(DATEDISPLAY, 6, 5, true); 3035 maxim.setLed(DATEDISPLAY, 6, 6, true); 3036 maxim.setLed(DATEDISPLAY, 6, 7, true); 3037 // display decimal point 3038 //maxim.setLed(DATEDISPLAY, 6, 0, true); 3039 break; 3040 case 6: // friday 3041 // clear display 3042 maxim.setChar(DATEDISPLAY, 7, ' ', false); 3043 maxim.setChar(DATEDISPLAY, 6, ' ', false); 3044 // display 't' 3045 maxim.setLed(DATEDISPLAY, 7, 1, true); 3046 maxim.setLed(DATEDISPLAY, 7, 5, true); 3047 maxim.setLed(DATEDISPLAY, 7, 6, true); 3048 maxim.setLed(DATEDISPLAY, 7, 7, true); 3049 // display 'r' 3050 maxim.setLed(DATEDISPLAY, 6, 5, true); 3051 maxim.setLed(DATEDISPLAY, 6, 7, true); 3052 // display decimal point 3053 //maxim.setLed(DATEDISPLAY, 6, 0, true); 3054 break; 3055 case 7: // saturday 3056 // clear display 3057 maxim.setChar(DATEDISPLAY, 7, ' ', false); 3058 maxim.setChar(DATEDISPLAY, 6, ' ', false); 3059 // display 'S' 3060 maxim.setLed(DATEDISPLAY, 7, 1, true); 3061 maxim.setLed(DATEDISPLAY, 7, 3, true); 3062 maxim.setLed(DATEDISPLAY, 7, 4, true); 3063 maxim.setLed(DATEDISPLAY, 7, 6, true); 3064 maxim.setLed(DATEDISPLAY, 7, 7, true); 3065 // display 'A' 3066 maxim.setLed(DATEDISPLAY, 6, 1, true); 3067 maxim.setLed(DATEDISPLAY, 6, 2, true); 3068 maxim.setLed(DATEDISPLAY, 6, 3, true); 3069 maxim.setLed(DATEDISPLAY, 6, 5, true); 3070 maxim.setLed(DATEDISPLAY, 6, 6, true); 3071 maxim.setLed(DATEDISPLAY, 6, 7, true); 3072 // display decimal point 3073 //maxim.setLed(DATEDISPLAY, 6, 0, true); 3074 break; 3075 } 3076 // display day and month 3077 maxim.setChar(DATEDISPLAY, 5, ' ', false); 3078 maxim.setChar(DATEDISPLAY, 4, day() / 10, false); 3079 maxim.setChar(DATEDISPLAY, 3, day() % 10, false); 3080 maxim.setChar(DATEDISPLAY, 2, '-', false); 3081 maxim.setChar(DATEDISPLAY, 1, month() / 10, false); 3082 maxim.setChar(DATEDISPLAY, 0, month() % 10, false); 3083 // maxim.setChar(DATEDISPLAY, 1, (year() - 2000) / 10, false); 3084 // maxim.setChar(DATEDISPLAY, 0, (year() - 2000) % 10, false); 3085} 3086 3087 3088/*************************************************************************************************************************************************** 3089 #### 3090 ###### ###### ## ## ####### ##### ## ###### ####### ## ## ###### ####### ## ## ###### ## ## ####### ## ## 3091 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 3092 ## ## ### ### ## ## ## #### ## ## ## ## ## ### ### ## ## ### ### ## ### ### 3093 ## ## ## # ## ##### ## ## ## # ## ##### ## ## ##### ## # ## ###### ## # ## ##### ## # ## 3094 ## ## ## # ## ## ## ## ###### ## ## ## ## ## ## # ## ## ## # ## ## ## # ## 3095 ## ## ## ## ## ## ## ## # ## ## ## ## ## ## ## ## ## ## ## ## ## 3096 ## ###### ## ## ####### ##### ### ## ## ####### ###### ## ####### ## ## ## ## ## ####### ## ## 3097 3098 3099****************************************************************************************************************************************************/ 3100// copy current time/date into temporary variables while adjusting 3101void timeDateToTemporaryMem() 3102{ 3103 TMPsecond = second(); 3104 TMPminute = minute(); 3105 TMPhour = hour(); 3106 TMPweekday = weekday(); 3107 TMPday = day(); 3108 TMPmonth = month(); 3109 TMPyear = (year() - 2000); // we don't need the 'century part', only last 2 digits 3110} 3111 3112 3113/* 3114 //---------------------------------------------------------------------------------------------------------- 3115 // during adjustment of the time/date, temporary variables are used (seconds are set to zero) 3116 // Ternary operator is used to blink the display which is adjusted 3117 // ( CONDITION ? Execute when TRUE : Execute when FALSE ) 3118 void displayTemporaryTime() 3119 { 3120 switch (state) 3121 { 3122 case SET_HOUR: 3123 maxim.setChar(TIMEDISPLAY, 7, (blinkDisplay == true) ? (TMPhour / 10) : ' ', false); // Adjust HOUR 3124 maxim.setChar(TIMEDISPLAY, 6, (blinkDisplay == true) ? (TMPhour % 10) : ' ', false); 3125 maxim.setChar(TIMEDISPLAY, 5, (TMPminute / 10), false); 3126 maxim.setChar(TIMEDISPLAY, 4, (TMPminute % 10), false); 3127 break; 3128 case SET_MINUTES: 3129 maxim.setChar(TIMEDISPLAY, 7, (TMPhour / 10), false); 3130 maxim.setChar(TIMEDISPLAY, 6, (TMPhour % 10), false); 3131 maxim.setChar(TIMEDISPLAY, 5, (blinkDisplay == true) ? (TMPminute / 10) : ' ', false); // Adjust MINUTES 3132 maxim.setChar(TIMEDISPLAY, 4, (blinkDisplay == true) ? (TMPminute % 10) : ' ', false); 3133 break; 3134 } 3135 3136 // Blink routine 3137 currentTime = millis(); 3138 if (currentTime - previousTime >= 500) 3139 { 3140 // reverse blinkDisplay state 3141 blinkDisplay == true ? blinkDisplay = false : blinkDisplay = true; 3142 // reset previousTime 3143 previousTime = millis(); 3144 } 3145 } 3146 3147 //---------------------------------------------------------------------------------------------------------- 3148 // during adjustment of the date, temporary variables are used 3149 // Ternary operator is used to blink the display which is adjusted 3150 // ( CONDITION ? Execute when TRUE : Execute when FALSE ) 3151 void displayTemporaryDate() 3152 { 3153 switch (state) 3154 { 3155 case SET_DAY: 3156 maxim.setChar(DATEDISPLAY, 7, (blinkDisplay == true) ? (TMPday / 10) : ' ', false); // Adjust DAY 3157 maxim.setChar(DATEDISPLAY, 6, (blinkDisplay == true) ? (TMPday % 10) : ' ', false); 3158 maxim.setChar(DATEDISPLAY, 5, '-', false); 3159 maxim.setChar(DATEDISPLAY, 4, (TMPmonth / 10), false); 3160 maxim.setChar(DATEDISPLAY, 3, (TMPmonth % 10), false); 3161 maxim.setChar(DATEDISPLAY, 2, '-', false); 3162 maxim.setChar(DATEDISPLAY, 1, (TMPyear / 10), false); 3163 maxim.setChar(DATEDISPLAY, 0, (TMPyear % 10), false); 3164 break; 3165 case SET_MONTH: 3166 maxim.setChar(DATEDISPLAY, 7, (TMPday / 10), false); 3167 maxim.setChar(DATEDISPLAY, 6, (TMPday % 10), false); 3168 maxim.setChar(DATEDISPLAY, 5, '-', false); 3169 maxim.setChar(DATEDISPLAY, 4, (blinkDisplay == true) ? (TMPmonth / 10) : ' ', false); // Adjust MONTH 3170 maxim.setChar(DATEDISPLAY, 3, (blinkDisplay == true) ? (TMPmonth % 10) : ' ', false); 3171 maxim.setChar(DATEDISPLAY, 2, '-', false); 3172 maxim.setChar(DATEDISPLAY, 1, (TMPyear / 10), false); 3173 maxim.setChar(DATEDISPLAY, 0, (TMPyear % 10), false); 3174 break; 3175 case SET_YEAR: 3176 maxim.setChar(DATEDISPLAY, 7, (TMPday / 10), false); 3177 maxim.setChar(DATEDISPLAY, 6, (TMPday % 10), false); 3178 maxim.setChar(DATEDISPLAY, 5, '-', false); 3179 maxim.setChar(DATEDISPLAY, 4, (TMPmonth / 10), false); 3180 maxim.setChar(DATEDISPLAY, 3, (TMPmonth % 10), false); 3181 maxim.setChar(DATEDISPLAY, 2, '-', false); 3182 maxim.setChar(DATEDISPLAY, 1, (blinkDisplay == true) ? (TMPyear / 10) : ' ', false); // Adjust YEAR 3183 maxim.setChar(DATEDISPLAY, 0, (blinkDisplay == true) ? (TMPyear % 10) : ' ', false); 3184 break; 3185 } 3186 3187 // Blink routine 3188 currentTime = millis(); 3189 if (currentTime - previousTime >= 500) 3190 { 3191 // reverse blinkDisplay state 3192 blinkDisplay == true ? blinkDisplay = false : blinkDisplay = true; 3193 // reset previousTime 3194 previousTime = millis(); 3195 } 3196 } 3197*/ 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219/*************************************************************************************************************************************************** 3220 3221 ###### ###### #### 3222 ## ## ## ## ## 3223 ## ## ## ## 3224 ###### ## ## 3225 ## ## ## ## 3226 ## ## ## ## ## 3227 ## ## ## #### 3228 3229****************************************************************************************************************************************************/ 3230 3231 3232 3233 3234/*************************************************************************************************************************************************** 3235 3236 ## ## ###### ###### ###### ####### ###### ###### #### 3237 ## ## ## ## ## ## ## ## ## ## ## ## 3238 ## # ## ## ## ## ## ## ## ## ## ## 3239 ## # ## ###### ## ## ##### ###### ## ## 3240 ## # ## ## ## ## ## ## ## ## ## ## 3241 ### ### ## ## ## ## ## ## ## ## ## ## 3242 ## ## ## ## ###### ## ####### ## ## ## #### 3243 3244****************************************************************************************************************************************************/ 3245void writeRTC() 3246{ 3247 Wire.beginTransmission(CHRONODOT_ADDRESS); 3248 //stop Oscillator 3249 Wire.write(0x00); 3250 //request 7 bytes (seconds, minutes, hour, weekday, date, month, year) 3251 Wire.write(dec2Bcd(TMPsecond)); 3252 Wire.write(dec2Bcd(TMPminute)); 3253 Wire.write(dec2Bcd(TMPhour)); 3254 Wire.write(TMPweekday); 3255 Wire.write(dec2Bcd(TMPday)); 3256 Wire.write(dec2Bcd(TMPmonth)); 3257 Wire.write(dec2Bcd(TMPyear)); 3258 // start oscillator 3259 Wire.write(0x00); 3260 Wire.endTransmission(); 3261} 3262 3263/*************************************************************************************************************************************************** 3264 3265 ###### ####### ## ##### ###### ###### #### 3266 ## ## ## ## ## ## ## ## ## ## ## 3267 ## ## ## #### ## ## ## ## ## ## 3268 ###### ##### ## # ## ## ###### ## ## 3269 ## ## ## ###### ## ## ## ## ## ## 3270 ## ## ## ## # ## ## ## ## ## ## ## 3271 ## ## ####### ### ## ##### ## ## ## #### 3272 3273****************************************************************************************************************************************************/ 3274void readRTC() 3275{ 3276 Wire.beginTransmission(CHRONODOT_ADDRESS); 3277 // send request to receive data starting at register 0 3278 Wire.write(0x00); 3279 Wire.endTransmission(); 3280 //request 7 bytes (seconds, minutes, hour, weekday, date, month, year) 3281 Wire.requestFrom(CHRONODOT_ADDRESS, 7); 3282 if (Wire.available() ) 3283 { 3284 TMPsecond = bcd2Dec( Wire.read() ); 3285 TMPminute = bcd2Dec( Wire.read() ); 3286 TMPhour = bcd2Dec( Wire.read() ); 3287 TMPweekday = bcd2Dec( Wire.read() ); 3288 TMPday = bcd2Dec( Wire.read() ); 3289 TMPmonth = bcd2Dec( Wire.read() ); 3290 TMPyear = bcd2Dec( Wire.read() ); 3291 } 3292} 3293 3294/*************************************************************************************************************************************************** 3295 3296 ###### ####### ## ##### ###### ###### #### ###### ####### ## ## ###### ####### ###### 3297 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 3298 ## ## ## #### ## ## ## ## ## ## ## ## ### ### ## ## ## ## ## 3299 ###### ##### ## # ## ## ###### ## ## ## ##### ## # ## ###### ##### ###### 3300 ## ## ## ###### ## ## ## ## ## ## ## ## ## # ## ## ## ## ## 3301 ## ## ## ## # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 3302 ## ## ####### ### ## ##### ## ## ## #### ## ####### ## ## ## ####### ## ## ## 3303 3304****************************************************************************************************************************************************/ 3305//void readRtcTemp() 3306//{ 3307// //temp registers (11h-12h) get updated automatically every 64s 3308// Wire.beginTransmission(CHRONODOT_ADDRESS); 3309// Wire.write(0x11); 3310// Wire.endTransmission(); 3311// // Just the two this time (temperature int, frac) 3312// Wire.requestFrom(CHRONODOT_ADDRESS, 2); 3313// if(Wire.available()) 3314// { 3315// int8_t fint = Wire.read(); 3316// uint8_t ffrac = ((Wire.read() >> 6)); 3317// 3318// temp3231 = (float)fint + ((float)ffrac * 0.25); 3319// } 3320//} 3321 3322/*************************************************************************************************************************************************** 3323 3324 ##### ####### ###### ###### ###### #### ##### ### ## ## 3325 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 3326 ## ## ## ## ## ## ## ## ## ## ## # ## 3327 ##### ##### ## ###### ## ## ##### ## ## ## # ## 3328 ## ## ## ## ## ## ## ## ## ## ## # ## 3329 ## ## ## ## ## ## ## ## ## ## ## ## ## ### ### 3330 ##### ####### ## ## ## ## #### ##### ### ## ## 3331 # ## # 3332 ## 3333****************************************************************************************************************************************************/ 3334void setRtcSquarewave() 3335{ 3336 //set control register to output square wave on pin 3 at 1Hz 3337 Wire.beginTransmission(CHRONODOT_ADDRESS); 3338 // set pointer to control register of DS3231 3339 Wire.write(0x0E); 3340 // bits 4 & 3 in ctrlByte set to 0 = 1Hz 3341 Wire.write(B00000000); 3342 Wire.endTransmission(); 3343} 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371/*************************************************************************************************************************************************** 3372 3373 ###### ####### ### ###### ####### ## ## ###### ####### ###### ## ###### ## ## ###### ####### 3374 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 3375 ## ## ## ## ## ## ## ### ### ## ## ## ## ## #### ## ## ## ## ## ## 3376 ###### ##### ## ## ## ##### ## # ## ###### ##### ###### ## # ## ## ## ###### ##### 3377 ## ## ## ## ## ## ## ## # ## ## ## ## ## ###### ## ## ## ## ## ## 3378 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## # ## ## ## ## ## ## 3379 ## ## ####### ### ## ## ####### ## ## ## ####### ## ## ### ## ## ##### ## ## ####### 3380 # ## # 3381 ## 3382****************************************************************************************************************************************************/ 3383void requestTemperature() 3384{ 3385 ds.reset(); // The initialization sequence consists of a reset pulse transmitted by the bus master followed by presence pulse(s) transmitted by the slave(s). 3386 //ds.skip(); // use this command when only 1 sensor is used to avoid specifying the address! 3387 ds.select(addr); // select specific device 3388 ds.write(0x44); // start conversion 3389} 3390 3391/*************************************************************************************************************************************************** 3392 3393 ###### ####### ## ##### ###### ####### ## ## ###### ####### ###### ## ###### ## ## ###### ####### 3394 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 3395 ## ## ## #### ## ## ## ## ### ### ## ## ## ## ## #### ## ## ## ## ## ## 3396 ###### ##### ## # ## ## ## ##### ## # ## ###### ##### ###### ## # ## ## ## ###### ##### 3397 ## ## ## ###### ## ## ## ## ## # ## ## ## ## ## ###### ## ## ## ## ## ## 3398 ## ## ## ## # ## ## ## ## ## ## ## ## ## ## ## # ## ## ## ## ## ## 3399 ## ## ####### ### ## ##### ## ####### ## ## ## ####### ## ## ### ## ## ##### ## ## ####### 3400 3401****************************************************************************************************************************************************/ 3402void readTemperature() 3403{ 3404 present = ds.reset(); // The return value of ds.reset() command is stored in the variable PRESENT - The initialization sequence consists of a reset pulse transmitted by the bus master followed by presence pulse(s) transmitted by the slave(s). 3405 //ds.skip(); // use this command when only 1 sensor is used to avoid specifying the address! 3406 ds.select(addr); // select specific device 3407 ds.write(0xBE); // Read Scratchpad 3408 3409 for ( tCount = 0; tCount < 9; tCount++) { // we need 9 bytes 3410 data[tCount] = ds.read(); // Read a Byte a a time 3411 } // for 3412 3413 // Convert the data to actual temperature 3414 // because the result is a 16 bit signed integer, it should 3415 // be stored to an "int16_t" type, which is always 16 bits 3416 // even when compiled on a 32 bit processor. 3417 int LowByte = data[0]; 3418 int HighByte = data[1]; 3419 int TempReading = (HighByte << 8) + LowByte; 3420 // celciusRaw is 4 digits; 2 whole, 2 fraction 3421 int celciusRaw = (6 * TempReading) + TempReading / 4; // multiply by (100 * 0.0625) or 6.25 3422 // round to one digit after decimal point 3423 celciusRaw % 10 >= 5 ? tempCelcius = (celciusRaw / 10) + 1 : tempCelcius = celciusRaw / 10; 3424 3425 3426 // reset temperature memory after startup 3427 if (startup == true) 3428 { 3429 minTemp = maxTemp = tempCelcius; 3430 minTempHour = maxTempHour = hour(); 3431 minTempMinute = maxTempMinute = minute(); 3432 } 3433 3434 3435 // check if min.temp. adjustment is needed 3436 if (minTemp > tempCelcius) 3437 { 3438 minTemp = tempCelcius; 3439 minTempHour = hour(); 3440 minTempMinute = minute(); 3441 } 3442 // check if max.temp. adjustment is needed 3443 if (maxTemp < tempCelcius) 3444 { 3445 maxTemp = tempCelcius; 3446 maxTempHour = hour(); 3447 maxTempMinute = minute(); 3448 } 3449} 3450 3451/*************************************************************************************************************************************************** 3452 3453 ###### ####### ## ##### ## ## ## ## ## ## ###### ##### ###### ###### ## ## 3454 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 3455 ## ## ## #### ## ## ## ## ## ## ### ### ## ## ## ## ## #### 3456 ###### ##### ## # ## ## ####### ## ## ## # ## ## ## ## ## ## ## 3457 ## ## ## ###### ## ## ## ## ## ## ## # ## ## ## ## ## ## ## 3458 ## ## ## ## # ## ## ## ## ## ## ## ## ## ## ## ## ## ## 3459 ## ## ####### ### ## ##### ## ## ##### ## ## ###### ##### ###### ## ## 3460 3461****************************************************************************************************************************************************/ 3462void readHumidity() 3463{ 3464 float humidityRaw = htu21df.readHumidity(); 3465 humidity = (humidityRaw * 10); 3466 3467 // reset humidity memory after startup 3468 if (startup == true) 3469 { 3470 minHumidity = maxHumidity = humidity; 3471 minHumidityHour = maxHumidityHour = hour(); 3472 minHumidityMinute = maxHumidityMinute = minute(); 3473 } 3474 3475 3476 // check if min.Humidity. adjustment is needed 3477 if (minHumidity > humidity) 3478 { 3479 minHumidity = humidity; 3480 minHumidityHour = hour(); 3481 minHumidityMinute = minute(); 3482 } 3483 // check if max.Humidity. adjustment is needed 3484 if (maxHumidity < humidity) 3485 { 3486 maxHumidity = humidity; 3487 maxHumidityHour = hour(); 3488 maxHumidityMinute = minute(); 3489 } 3490 3491} 3492 3493/*************************************************************************************************************************************************** 3494 3495 ###### ####### ## ##### ###### ###### ####### ##### ##### ## ## ###### ####### 3496 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 3497 ## ## ## #### ## ## ## ## ## ## ## ## ## ## ## ## ## ## 3498 ###### ##### ## # ## ## ###### ###### ##### ##### ##### ## ## ###### ##### 3499 ## ## ## ###### ## ## ## ## ## ## ## ## ## ## ## ## ## 3500 ## ## ## ## # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 3501 ## ## ####### ### ## ##### ## ## ## ####### ##### ##### ##### ## ## ####### 3502 3503****************************************************************************************************************************************************/ 3504void readPressure() 3505{ 3506 pressureSample = 0; 3507 for (int i = 0; i < 3; i++) // get 3 samples to gt rid of erratic readings 3508 { 3509 pressureSample += bmp183.getPressure(); // read pressure 3510 delay(1); 3511 } 3512 pressure = (pressureSample / 3); // devide to get mean value and dividee by 10 to get 1 digit accuracy 3513 pressure % 10 >= 5 ? (pressure = (pressure / 10) + 1) : (pressure = pressure / 10); 3514 3515 //debug with potentiometer 3516 //pressure = map(analogRead(A3), 0, 1023, 9500, 10500); 3517} 3518 3519 3520/*************************************************************************************************************************************************** 3521 3522 ##### ###### ### ###### ####### ###### ###### ####### ##### ##### ## ## ###### ####### 3523 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 3524 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 3525 ##### ## ## ## ###### ##### ###### ###### ##### ##### ##### ## ## ###### ##### 3526 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 3527 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 3528 ##### ## ### ## ## ####### ## ## ## ####### ##### ##### ##### ## ## ####### 3529 3530****************************************************************************************************************************************************/ 3531void storePressure() 3532{ 3533 // store pressure data in memory every 12 minutes 3534 barometerData[130] = pressure; // store pressure value in last position of the array 3535 //store new value in array, shift all data, First In First Out 3536 for (int rp = 0 ; rp < 130; rp++) 3537 { 3538 barometerData[rp] = barometerData[rp + 1]; // replace array value with the next array value 3539 } 3540 // set flag so tft display can be updated 3541 pressureDataUpdated = true; 3542} 3543 3544/*************************************************************************************************************************************************** 3545 3546 3547 3548 EEPROM PR WRITE 3549 3550 3551 3552****************************************************************************************************************************************************/ 3553void eepromWritePressureData() 3554{ 3555 int startAddress = BAROGRAPH_START_ADDRESS; //this will increment after each write 3556 3557 for (int i = 0; i <= 130; i++) 3558 { 3559 startAddress += writeObjectSimple(EEPROM_ADDRESS, startAddress, barometerData[i]); 3560 } 3561} 3562 3563/*************************************************************************************************************************************************** 3564 3565 3566 3567 EEPROM PR READ 3568 3569 3570 3571****************************************************************************************************************************************************/ 3572void eepromReadPressureData() 3573{ 3574 int startAddress = BAROGRAPH_START_ADDRESS; //this will increment after each write 3575 // read barometerData array 3576 for (int i = 0; i <= 130; i++) 3577 { 3578 startAddress += readObjectSimple(EEPROM_ADDRESS, startAddress, barometerData[i]); 3579 } 3580} 3581 3582 3583/*************************************************************************************************************************************************** 3584 3585 } 3586 3587 /*************************************************************************************************************************************************** 3588 3589 #### ## ## #### ###### ## ###### ### ###### ###### ####### ## ## ##### 3590 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ### ## ## ## 3591 ## #### ## ## ## ## #### ## ## ## ## ## ## ## ## ### ## ## ## 3592 ## ## # ## ## ###### ## # ###### ## ## ## ###### ##### ## # ## ## ## 3593 ## ###### ## ## ## ## ###### ## ## ## ## ## ## ## ## ## # ## ## ## 3594 ## ## ## # ## ## ## ## ## ## # ## ## ## ## ## ## ## ## ## ### ## ## 3595 #### ### ## ###### #### ###### ### ## ## ## ### ## ## ## ####### ## ## ##### 3596 3597****************************************************************************************************************************************************/ 3598void calculateBaroTrend() 3599{ 3600 // check if barometer pressure value of 3 hours ago has valid data (one array value = 12 minutes * 15 = 3 hours) 3601 if (barometerData[130 - 15] < 900) // DEBUG, 1 MOET 15 ZIJN 3602 { 3603 // no valid data yet 3604 baroTrendValue = 0; 3605 baroTrend = NA; 3606 } 3607 else 3608 { 3609 // valid data available 3610 baroTrendValue = barometerData[130] - barometerData[130 - 15];// DEBUG, 1 MOET 15 ZIJN 3611 3612 // Serial << "CALC BARO TREND after calc of barotrendValue " << endl; 3613 // Serial << "-------------------------------------------------" << endl; 3614 // Serial << "time hh:mm:ss : " << hour() << ":" << minute() << ":" << second() << endl; 3615 // Serial << "baroTrendValue : " << baroTrendValue/10 << "." << baroTrendValue%10 << endl; 3616 // Serial << "pressure : " << pressure << endl; 3617 // Serial << "barometerData[130] : " << barometerData[130] << endl; 3618 // Serial << "barometerData[130-1] : " << barometerData[130 - 2] << endl; 3619 // Serial << endl; 3620 3621 // check barometerTrend 3622 if (baroTrendValue >= 60) // Barometric pressure RISING VERY QUICKLY 3623 { 3624 baroTrend = ZEER_SNEL_STIJGEND; 3625 } 3626 else if (baroTrendValue >= 36) // Barometric pressure RISING QUICKLY 3627 { 3628 baroTrend = SNEL_STIJGEND; 3629 } 3630 else if (baroTrendValue >= 16) // Barometric pressure RISING 3631 { 3632 baroTrend = STIJGEND; 3633 } 3634 else if (baroTrendValue > 1) // Barometric pressure RISING SLOWLY 3635 { 3636 baroTrend = LANGZAAM_STIJGEND; 3637 } 3638 else if ((baroTrendValue <= 1) && (baroTrendValue >= -1)) // Barometric pressure STEADY 3639 { 3640 baroTrend = STABIEL; 3641 } 3642 else if (baroTrendValue <= -60) // Barometric pressure FALLING VERY QUICKLY 3643 { 3644 baroTrend = ZEER_SNEL_DALEND; 3645 } 3646 else if (baroTrendValue <= -36) // Barometric pressure FALLING QUICKLY 3647 { 3648 baroTrend = SNEL_DALEND; 3649 } 3650 else if (baroTrendValue <= -16) // Barometric pressure FALLING 3651 { 3652 baroTrend = DALEND; 3653 } 3654 else if (baroTrendValue < -1) // Barometric pressure FALLING SLOWLY 3655 { 3656 baroTrend = LANGZAAM_DALEND; 3657 } 3658 }// else 3659 3660 3661}// void 3662 3663 3664/*************************************************************************************************************************************************** 3665 ## 3666 ##### ###### ## ## ## ###### ###### ####### ## ## ##### ## ####### ##### # ##### 3667 ## ## ## ## ## ## ## ## ## ## ## ### ## ## ## ## ## ## ## # ## ## 3668 ## ## ## ## #### ## # ## ## ## ## ## ### ## ## ## ## ## ## ## ## 3669 ## ## ###### ## # ## # ## ## ###### ##### ## # ## ## ## ## ##### ## ## ##### 3670 ## ## ## ## ###### ## # ## ## ## ## ## ## # ## ## ## ## ## ## ## ## 3671 ## ## ## ## ## # ### ### ## ## ## ## ## ### ## ## ## ## ## ## ## ## 3672 ##### ## ## ### ## ## ## ## ## ## ####### ## ## ##### ###### ####### ##### ##### 3673 3674***************************************************************************************************************************************************/ 3675void drawTrendIndicators() 3676{ 3677 // clear trend indicator graphics 3678 3679 // ZEER_SNEL_STIJGEND: 3680 tft.drawFastHLine(132 , 84, 28, DGRAY); 3681 tft.drawFastHLine(133 , 85, 27, DGRAY); 3682 tft.drawFastHLine(134 , 86, 26, DGRAY); 3683 tft.drawFastHLine(135 , 87, 25, DGRAY); 3684 // SNEL_STIJGEND: 3685 tft.drawFastHLine(137 , 89, 23, DGRAY); 3686 tft.drawFastHLine(138 , 90, 22, DGRAY); 3687 tft.drawFastHLine(139 , 91, 21, DGRAY); 3688 tft.drawFastHLine(140 , 92, 20, DGRAY); 3689 // STIJGEND: 3690 tft.drawFastHLine(142 , 94, 18, DGRAY); 3691 tft.drawFastHLine(143 , 95, 17, DGRAY); 3692 tft.drawFastHLine(144 , 96, 16, DGRAY); 3693 tft.drawFastHLine(145 , 97, 15, DGRAY); 3694 // LANGZAAM_STIJGEND: 3695 tft.drawFastHLine(147 , 99, 13, DGRAY); 3696 tft.drawFastHLine(148 , 100, 12, DGRAY); 3697 tft.drawFastHLine(149 , 101, 11, DGRAY); 3698 tft.drawFastHLine(150 , 102, 10, DGRAY); 3699 // STABIEL: 3700 tft.drawFastHLine(151 , 104, 9, DGRAY); 3701 tft.drawFastHLine(151 , 105, 9, DGRAY); 3702 tft.drawFastHLine(151 , 106, 9, DGRAY); 3703 tft.drawFastHLine(151 , 107, 9, DGRAY); 3704 // LANGZAAM_DALEND: 3705 tft.drawFastHLine(150 , 109, 10, DGRAY); 3706 tft.drawFastHLine(149 , 110, 11, DGRAY); 3707 tft.drawFastHLine(148 , 111, 12, DGRAY); 3708 tft.drawFastHLine(147 , 112, 13, DGRAY); 3709 // DALEND: 3710 tft.drawFastHLine(145 , 114, 15, DGRAY); 3711 tft.drawFastHLine(144 , 115, 16, DGRAY); 3712 tft.drawFastHLine(143 , 116, 17, DGRAY); 3713 tft.drawFastHLine(142 , 117, 18, DGRAY); 3714 // SNEL_DALEND: 3715 tft.drawFastHLine(140 , 119, 20, DGRAY); 3716 tft.drawFastHLine(139 , 120, 21, DGRAY); 3717 tft.drawFastHLine(138 , 121, 22, DGRAY); 3718 tft.drawFastHLine(137 , 122, 23, DGRAY); 3719 // ZEER_SNEL_DALEND: 3720 tft.drawFastHLine(135 , 124, 25, DGRAY); 3721 tft.drawFastHLine(134 , 125, 26, DGRAY); 3722 tft.drawFastHLine(133 , 126, 27, DGRAY); 3723 tft.drawFastHLine(132 , 127, 28, DGRAY); 3724 3725 // display barometric trend graphics 3726 switch (baroTrend) 3727 { 3728 case NA: 3729 // display nothing for now ;) 3730 break; 3731 case ZEER_SNEL_STIJGEND: 3732 tft.drawFastHLine(132 , 84, 28, GREEN); 3733 tft.drawFastHLine(133 , 85, 27, GREEN); 3734 tft.drawFastHLine(134 , 86, 26, GREEN); 3735 tft.drawFastHLine(135 , 87, 25, GREEN); 3736 3737 tft.drawFastHLine(137 , 89, 23, GREEN); 3738 tft.drawFastHLine(138 , 90, 22, GREEN); 3739 tft.drawFastHLine(139 , 91, 21, GREEN); 3740 tft.drawFastHLine(140 , 92, 20, GREEN); 3741 3742 tft.drawFastHLine(142 , 94, 18, GREEN); 3743 tft.drawFastHLine(143 , 95, 17, GREEN); 3744 tft.drawFastHLine(144 , 96, 16, GREEN); 3745 tft.drawFastHLine(145 , 97, 15, GREEN); 3746 3747 tft.drawFastHLine(147 , 99, 13, GREEN); 3748 tft.drawFastHLine(148 , 100, 12, GREEN); 3749 tft.drawFastHLine(149 , 101, 11, GREEN); 3750 tft.drawFastHLine(150 , 102, 10, GREEN); 3751 break; 3752 case SNEL_STIJGEND: 3753 tft.drawFastHLine(137 , 89, 23, GREEN); 3754 tft.drawFastHLine(138 , 90, 22, GREEN); 3755 tft.drawFastHLine(139 , 91, 21, GREEN); 3756 tft.drawFastHLine(140 , 92, 20, GREEN); 3757 3758 tft.drawFastHLine(142 , 94, 18, GREEN); 3759 tft.drawFastHLine(143 , 95, 17, GREEN); 3760 tft.drawFastHLine(144 , 96, 16, GREEN); 3761 tft.drawFastHLine(145 , 97, 15, GREEN); 3762 3763 tft.drawFastHLine(147 , 99, 13, GREEN); 3764 tft.drawFastHLine(148 , 100, 12, GREEN); 3765 tft.drawFastHLine(149 , 101, 11, GREEN); 3766 tft.drawFastHLine(150 , 102, 10, GREEN); 3767 break; 3768 case STIJGEND: 3769 tft.drawFastHLine(142 , 94, 18, GREEN); 3770 tft.drawFastHLine(143 , 95, 17, GREEN); 3771 tft.drawFastHLine(144 , 96, 16, GREEN); 3772 tft.drawFastHLine(145 , 97, 15, GREEN); 3773 3774 tft.drawFastHLine(147 , 99, 13, GREEN); 3775 tft.drawFastHLine(148 , 100, 12, GREEN); 3776 tft.drawFastHLine(149 , 101, 11, GREEN); 3777 tft.drawFastHLine(150 , 102, 10, GREEN); 3778 break; 3779 case LANGZAAM_STIJGEND: 3780 tft.drawFastHLine(147 , 99, 13, GREEN); 3781 tft.drawFastHLine(148 , 100, 12, GREEN); 3782 tft.drawFastHLine(149 , 101, 11, GREEN); 3783 tft.drawFastHLine(150 , 102, 10, GREEN); 3784 break; 3785 case STABIEL: 3786 tft.drawFastHLine(151 , 104, 9, YELLOW); 3787 tft.drawFastHLine(151 , 105, 9, YELLOW); 3788 tft.drawFastHLine(151 , 106, 9, YELLOW); 3789 tft.drawFastHLine(151 , 107, 9, YELLOW); 3790 break; 3791 case LANGZAAM_DALEND: 3792 tft.drawFastHLine(150 , 109, 10, RED); 3793 tft.drawFastHLine(149 , 110, 11, RED); 3794 tft.drawFastHLine(148 , 111, 12, RED); 3795 tft.drawFastHLine(147 , 112, 13, RED); 3796 break; 3797 case DALEND: 3798 tft.drawFastHLine(150 , 109, 10, RED); 3799 tft.drawFastHLine(149 , 110, 11, RED); 3800 tft.drawFastHLine(148 , 111, 12, RED); 3801 tft.drawFastHLine(147 , 112, 13, RED); 3802 3803 tft.drawFastHLine(145 , 114, 15, RED); 3804 tft.drawFastHLine(144 , 115, 16, RED); 3805 tft.drawFastHLine(143 , 116, 17, RED); 3806 tft.drawFastHLine(142 , 117, 18, RED); 3807 break; 3808 case SNEL_DALEND: 3809 tft.drawFastHLine(150 , 109, 10, RED); 3810 tft.drawFastHLine(149 , 110, 11, RED); 3811 tft.drawFastHLine(148 , 111, 12, RED); 3812 tft.drawFastHLine(147 , 112, 13, RED); 3813 3814 tft.drawFastHLine(145 , 114, 15, RED); 3815 tft.drawFastHLine(144 , 115, 16, RED); 3816 tft.drawFastHLine(143 , 116, 17, RED); 3817 tft.drawFastHLine(142 , 117, 18, RED); 3818 3819 tft.drawFastHLine(140 , 119, 20, RED); 3820 tft.drawFastHLine(139 , 120, 21, RED); 3821 tft.drawFastHLine(138 , 121, 22, RED); 3822 tft.drawFastHLine(137 , 122, 23, RED); 3823 break; 3824 case ZEER_SNEL_DALEND: 3825 tft.drawFastHLine(150 , 109, 10, RED); 3826 tft.drawFastHLine(149 , 110, 11, RED); 3827 tft.drawFastHLine(148 , 111, 12, RED); 3828 tft.drawFastHLine(147 , 112, 13, RED); 3829 3830 tft.drawFastHLine(145 , 114, 15, RED); 3831 tft.drawFastHLine(144 , 115, 16, RED); 3832 tft.drawFastHLine(143 , 116, 17, RED); 3833 tft.drawFastHLine(142 , 117, 18, RED); 3834 3835 tft.drawFastHLine(140 , 119, 20, RED); 3836 tft.drawFastHLine(139 , 120, 21, RED); 3837 tft.drawFastHLine(138 , 121, 22, RED); 3838 tft.drawFastHLine(137 , 122, 23, RED); 3839 3840 tft.drawFastHLine(135 , 124, 25, RED); 3841 tft.drawFastHLine(134 , 125, 26, RED); 3842 tft.drawFastHLine(133 , 126, 27, RED); 3843 tft.drawFastHLine(132 , 127, 28, RED); 3844 break; 3845 }// switch 3846}// void 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881/*************************************************************************************************************************************************** 3882 3883 ##### ###### ## ## ## #### ###### ###### ##### ## ###### ## ## ####### ##### 3884 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ### ## ## ## ## 3885 ## ## ## ## #### ## # ## ## ## ## ## ## ## ## ## ### ## ## ## 3886 ## ## ###### ## # ## # ## ## ###### ## ## ## ## ## ## # ## ##### ##### 3887 ## ## ## ## ###### ## # ## ## ### ## ## ## ## ## ## ## ## # ## ## ## 3888 ## ## ## ## ## # ### ### ## ## ## ## ## ## ## ## ## ## ### ## ## ## 3889 ##### ## ## ### ## ## ## ##### ## ## ###### ##### ###### ###### ## ## ####### ##### 3890 3891****************************************************************************************************************************************************/ 3892void drawGridLines() 3893{ 3894 /*-------{ plot horizontal grid lines on TFT display }--------------------*/ 3895 for ( q = 0; q <= (plotLimitH) / grid24HlinePixelSpacing; q++) 3896 { 3897 tft.drawPixel(q * grid24HlinePixelSpacing, grid24HstartpositionYaxis + (0 * grid24HlineSpacing), GRIDCOLOR); 3898 tft.drawPixel(q * grid24HlinePixelSpacing, grid24HstartpositionYaxis + (1 * grid24HlineSpacing), GRIDCOLOR); 3899 tft.drawPixel(q * grid24HlinePixelSpacing, grid24HstartpositionYaxis + (2 * grid24HlineSpacing), GRIDCOLOR); 3900 tft.drawPixel(q * grid24HlinePixelSpacing, grid24HstartpositionYaxis + (3 * grid24HlineSpacing), GRIDCOLOR); 3901 tft.drawPixel(q * grid24HlinePixelSpacing, grid24HstartpositionYaxis + (4 * grid24HlineSpacing), GRIDCOLOR); 3902 } 3903 /*-------{ plot horizontal grid lines on TFT display }--------------------*/ 3904 for ( q = 0; q <= (plotLimitV - grid24VstartpositionYaxis) / grid24VlinePixelSpacing; q++) 3905 { 3906 tft.drawPixel(grid24VstartpositionXaxis + (0 * grid24VlineSpacing), ((grid24VstartpositionYaxis) + (q * grid24VlinePixelSpacing)), GRIDCOLOR); 3907 tft.drawPixel(grid24VstartpositionXaxis + (1 * grid24VlineSpacing), ((grid24VstartpositionYaxis) + (q * grid24VlinePixelSpacing)), GRIDCOLOR); 3908 tft.drawPixel(grid24VstartpositionXaxis + (2 * grid24VlineSpacing), ((grid24VstartpositionYaxis) + (q * grid24VlinePixelSpacing)), GRIDCOLOR); 3909 tft.drawPixel(grid24VstartpositionXaxis + (3 * grid24VlineSpacing), ((grid24VstartpositionYaxis) + (q * grid24VlinePixelSpacing)), GRIDCOLOR); 3910 tft.drawPixel(grid24VstartpositionXaxis + (4 * grid24VlineSpacing), ((grid24VstartpositionYaxis) + (q * grid24VlinePixelSpacing)), GRIDCOLOR); 3911 tft.drawPixel(grid24VstartpositionXaxis + (5 * grid24VlineSpacing), ((grid24VstartpositionYaxis) + (q * grid24VlinePixelSpacing)), GRIDCOLOR); 3912 } 3913} 3914 3915/*************************************************************************************************************************************************** 3916 3917 ##### ###### ## ## ## #### ###### ###### ##### ###### ###### #### ## ## ##### 3918 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 3919 ## ## ## ## #### ## # ## ## ## ## ## ## ## ## ## ## ## ## ## 3920 ## ## ###### ## # ## # ## ## ###### ## ## ## ## ## ## #### ##### 3921 ## ## ## ## ###### ## # ## ## ### ## ## ## ## ## ## ## ## ## ## ## 3922 ## ## ## ## ## # ### ### ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 3923 ##### ## ## ### ## ## ## ##### ## ## ###### ##### ## ###### #### ## ## ##### 3924 3925****************************************************************************************************************************************************/ 3926/*-------{ plot grid ticks on TFT display }--------------------*/ 3927void drawGridTicks() 3928{ 3929 // X axis solid line 3930 tft.drawFastHLine(0, plotLimitV, plotLimitH, XAXISCOLOR); 3931 // 1 hour ticks 3932 for ( q = 0; q <= (plotLimitH - grid24XaxisTicksStart) / grid24HlinePixelSpacing1H; q++) 3933 { 3934 tft.drawPixel(grid24XaxisTicksStart + q * grid24HlinePixelSpacing1H, plotLimitV + 1, XAXISCOLOR); 3935 } 3936 // 2 hour H ticks 3937 for ( q = 0; q <= (plotLimitH - grid24XaxisTicksStart) / grid24HlinePixelSpacing2H; q++) 3938 { 3939 tft.drawPixel(grid24XaxisTicksStart + 5 + q * grid24HlinePixelSpacing4H, plotLimitV + 2, XAXISCOLOR); 3940 tft.drawPixel(grid24XaxisTicksStart + 5 + q * grid24HlinePixelSpacing4H, plotLimitV + 3, XAXISCOLOR); 3941 } 3942 3943 // Y axis solid line 3944 tft.drawFastVLine(plotLimitH, grid24VstartpositionYaxis, plotLimitV - grid24VstartpositionXaxis, YAXISCOLOR); 3945 // 5Hpa V ticks 3946 for ( q = 0; q <= (plotLimitV - grid24HstartpositionYaxis) / grid24VlinePixelSpacing5Hpa; q++) 3947 { 3948 tft.drawPixel(plotLimitH + 1, grid24HstartpositionYaxis + (q * grid24VlinePixelSpacing5Hpa), YAXISCOLOR); 3949 } 3950 // 10Hpa Vticks 3951 for ( q = 0; q <= (plotLimitV - grid24HstartpositionYaxis) / grid24VlinePixelSpacing10Hpa; q++) 3952 { 3953 tft.drawPixel(plotLimitH + 2, grid24HstartpositionYaxis + (q * grid24VlinePixelSpacing10Hpa), YAXISCOLOR); 3954 tft.drawPixel(plotLimitH + 3, grid24HstartpositionYaxis + (q * grid24VlinePixelSpacing10Hpa), YAXISCOLOR); 3955 } 3956} 3957 3958 3959/*************************************************************************************************************************************************** 3960 3961 ##### ###### ## ## ## #### ###### ###### ##### ###### ####### ## ## ###### 3962 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 3963 ## ## ## ## #### ## # ## ## ## ## ## ## ## ## ## #### ## 3964 ## ## ###### ## # ## # ## ## ###### ## ## ## ## ##### ## ## 3965 ## ## ## ## ###### ## # ## ## ### ## ## ## ## ## ## ## #### ## 3966 ## ## ## ## ## # ### ### ## ## ## ## ## ## ## ## ## ## ## ## 3967 ##### ## ## ### ## ## ## ##### ## ## ###### ##### ## ####### ## ## ## 3968 3969****************************************************************************************************************************************************/ 3970 3971/*-------{ plot grid text lines on TFT display }--------------------*/ 3972void drawGridText() 3973{ 3974 tft.setTextSize(1); 3975 // draw X text 3976 tft.setTextColor(XTEXTCOLOR, BLACK); 3977 tft.setCursor(5, 121); 3978 tft << "24"; 3979 tft.setCursor(25, 121); 3980 tft << "20"; 3981 tft.setCursor(45, 121); 3982 tft << "16"; 3983 tft.setCursor(65, 121); 3984 tft << "12"; 3985 tft.setCursor(88, 121); 3986 tft << "8"; 3987 tft.setCursor(108, 121); 3988 tft << "4"; 3989 tft.setCursor(128, 121); 3990 tft << "0"; 3991 3992 // draw negative signs 3993 tft.drawFastHLine(1, 124, 3, XTEXTCOLOR); 3994 tft.drawFastHLine(1 + grid24HlineSpacing * 1, 124, 3, XTEXTCOLOR); 3995 tft.drawFastHLine(2 + grid24HlineSpacing * 2, 124, 3, XTEXTCOLOR); 3996 tft.drawFastHLine(2 + grid24HlineSpacing * 3, 124, 3, XTEXTCOLOR); 3997 tft.drawFastHLine(4 + grid24HlineSpacing * 4, 124, 3, XTEXTCOLOR); 3998 tft.drawFastHLine(4 + grid24HlineSpacing * 5, 124, 3, XTEXTCOLOR); 3999 4000 // draw Y text 4001 tft.setTextColor(YTEXTCOLOR, BLACK); 4002 tft.setCursor(plotLimitH + 6, grid24HstartpositionYaxis - 3); 4003 tft << (highScale == true ? "1050" : "1030"); 4004 tft.setCursor(plotLimitH + 6, (grid24HstartpositionYaxis - 3) + (1 * grid24HlineSpacing)); 4005 tft << (highScale == true ? "1030" : "1020"); 4006 tft.setCursor(plotLimitH + 6, (grid24HstartpositionYaxis - 3) + (2 * grid24HlineSpacing)); 4007 tft << (highScale == true ? "1010" : "1010"); 4008 tft.setCursor(plotLimitH + 6, (grid24HstartpositionYaxis - 3) + (3 * grid24HlineSpacing)); 4009 tft << (highScale == true ? " 990" : "1000"); 4010 tft.setCursor(plotLimitH + 6, (grid24HstartpositionYaxis - 3) + (4 * grid24HlineSpacing)); 4011 tft << (highScale == true ? " 970" : " 990"); 4012 tft.setCursor(plotLimitH + 6, (grid24HstartpositionYaxis - 3) + (5 * grid24HlineSpacing)); 4013 tft << (highScale == true ? " 950" : " 980"); 4014} 4015 4016/*************************************************************************************************************************************************** 4017 4018 ##### ###### ## ## ## ##### ####### ###### ###### ## ## ####### ## ## ## ## 4019 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ### ## ## ## 4020 ## ## ## ## #### ## # ## ## ## ## ## ### ### ## ### ## ## ## 4021 ## ## ###### ## # ## # ## ##### ##### ## ## ## # ## ##### ## # ## ## ## 4022 ## ## ## ## ###### ## # ## ## ## ## ## ## # ## ## ## # ## ## ## 4023 ## ## ## ## ## # ### ### ## ## ## ## ## ## ## ## ## ## ### ## ## 4024 ##### ## ## ### ## ## ## ##### ####### ## ## ## ## ## ####### ## ## ##### 4025 4026****************************************************************************************************************************************************/ 4027void drawSettingsMenu() 4028{ 4029 drawSettingsMenuHeader(); 4030 drawSettingsMenuAlarmTime(); 4031 drawSettingsMenuSecondsRing(); 4032 drawSettingsMenuLcdMode(); 4033 drawSettingsMenuTimeSet(); 4034 drawSettingsMenuDateSet(); 4035 drawSettingsMenuBarograph(); 4036} 4037 4038 4039void drawSettingsMenuHeader() 4040{ 4041 tft.fillRect(0, 0, 160, 9, GREEN); 4042 4043 tft.setTextSize(1); 4044 tft.setCursor(30, 1); 4045 tft.setTextColor(BLACK, GREEN); 4046 tft << "INSTELLINGEN MENU"; 4047} 4048 4049void drawSettingsMenuAlarmTime() 4050{ 4051 //////////////////////////////////////////////////////////////////////// ALARM TIME 4052 tft.setCursor(0, 11); 4053 tft.setTextColor( (currState == STATE_MENU_ALARM_TIME || currState == STATE_MENU_SET_ALARM_HOUR || currState == STATE_MENU_SET_ALARM_MINUTES ? CYAN : WHITE), BLACK); 4054 tft << "WEKTIJD"; 4055 tft.drawFastHLine(0, 18, 75, (currState == STATE_MENU_ALARM_TIME || currState == STATE_MENU_SET_ALARM_HOUR || currState == STATE_MENU_SET_ALARM_MINUTES ? CYAN : GREEN)); 4056 //itemnumber 1 4057 tft.setCursor(1, 20); 4058 tft.setTextColor( (currState == STATE_MENU_SET_ALARM_HOUR ? RED : YELLOW), BLACK); 4059 tft << alarmHour << ":"; 4060 //itemnumber 2 4061 tft.setCursor((alarmMinute < 10 ? 25 : 19), 20); 4062 tft.setTextColor( (currState == STATE_MENU_SET_ALARM_MINUTES ? RED : YELLOW), BLACK); 4063 tft << alarmMinute; 4064} 4065 4066 4067void drawSettingsMenuSecondsRing() 4068{ 4069 //////////////////////////////////////////////////////////////////////// SECONDS RING 4070 tft.setCursor(0, 33); 4071 tft.setTextColor( (currState == STATE_MENU_SECONDS_RING ? CYAN : WHITE), BLACK); 4072 tft << "LED RING"; 4073 tft.drawFastHLine(0, 40, 75, (currState == STATE_MENU_SECONDS_RING ? CYAN : GREEN) ); 4074 4075 tft.setCursor(1, 42); 4076 tft.setTextColor(YELLOW, BLACK); 4077 tft << (secondsRingFull == true ? "RING" : "PUNT"); 4078 4079} 4080 4081void drawSettingsMenuLcdMode() 4082{ 4083 //////////////////////////////////////////////////////////////////////// LCD MODE 4084 tft.setCursor(0, 55); 4085 tft.setTextColor( (currState == STATE_MENU_LCD_MODE ? CYAN : WHITE), BLACK); 4086 tft << "LCD MODUS"; 4087 tft.drawFastHLine(0, 62, 75, (currState == STATE_MENU_LCD_MODE ? CYAN : GREEN) ); 4088 4089 tft.setCursor(1, 64); 4090 tft.setTextColor(YELLOW, BLACK); 4091 tft << (lcdScrollModeAuto == true ? "DIASHOW" : "HANDMATIG"); 4092} 4093 4094void drawSettingsMenuTimeSet() 4095{ 4096 //////////////////////////////////////////////////////////////////////// TIME SET 4097 tft.setCursor(0, 77); 4098 tft.setTextColor( (currState == STATE_MENU_TIME ? CYAN : WHITE), BLACK); 4099 tft << "TIJD SET"; 4100 tft.drawFastHLine(0, 84, 75, (currState == STATE_MENU_TIME ? CYAN : GREEN) ); 4101 4102 tft.setCursor(1, 86); 4103 tft.setTextColor(YELLOW, BLACK); 4104 hour() < 10 ? (tft << " " << hour()) : tft << hour(); 4105 tft << ":"; 4106 minute() < 10 ? (tft << "0" << minute()) : tft << minute(); 4107} 4108 4109void drawSettingsMenuDateSet() 4110{ 4111 //////////////////////////////////////////////////////////////////////// DATE SET 4112 tft.setCursor(0, 99); 4113 tft.setTextColor( (currState == STATE_MENU_DATE ? CYAN : WHITE), BLACK); 4114 tft << "DATUM SET"; 4115 tft.drawFastHLine(0, 106, 75, (currState == STATE_MENU_DATE ? CYAN : GREEN) ); 4116 4117 tft.setCursor(1, 108); 4118 tft.setTextColor(YELLOW, BLACK); 4119 day() < 10 ? (tft << "0" << day()) : tft << day(); 4120 tft << "-"; 4121 month() < 10 ? (tft << "0" << month()) : tft << month(); 4122 tft << "-"; 4123 tft << year(); 4124} 4125 4126//bbbbb 4127void drawSettingsMenuBarograph() 4128{ 4129 //////////////////////////////////////////////////////////////////////// BAROGRAPH 4130 tft.setCursor(83, 77); 4131 tft.setTextColor( (currState == STATE_MENU_BAROGRAPH ? CYAN : WHITE), BLACK); 4132 tft << "BAROGRAAF"; 4133 tft.drawFastHLine(83, 84, 75, (currState == STATE_MENU_BAROGRAPH ? CYAN : GREEN) ); 4134 4135 tft.setTextColor(WHITE, BLACK); 4136 tft.setCursor(83, 86); 4137 tft << "MSLP:"; 4138 tft.setCursor(123, 86); 4139 tft.setTextColor(YELLOW, BLACK); 4140 tft << meanSeaLevelPressure / 10 << "." << meanSeaLevelPressure % 10; 4141 4142 tft.setTextColor(WHITE, BLACK); 4143 tft.setCursor(83, 95); 4144 tft << "Corr:"; 4145 4146 tft.setCursor(135, 95); 4147 tft << pressureCorrection; 4148} 4149 4150 4151/*************************************************************************************************************************************************** 4152 4153 ##### ###### ## ## ## ##### ## ## ###### ## ####### ## ## 4154 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 4155 ## ## ## ## #### ## # ## ## ### ### ## ## ## #### 4156 ## ## ###### ## # ## # ## ##### ## # ## ## ## ##### ## 4157 ## ## ## ## ###### ## # ## ## ## # ## ## ## ## ## 4158 ## ## ## ## ## # ### ### ## ## ## ## ## ## ## ## 4159 ##### ## ## ### ## ## ## ##### ## ## ###### ###### ####### ## 4160 4161***************************************************************************************************************************************************/ 4162void redSmiley(int posX, int posY) 4163{ 4164 4165 // draw smiley 4166 tft.fillCircle(posX, posY, 17, RED); 4167 //draw eyes 4168 tft.fillCircle(posX - 8, posY - 5, 2, BLACK); 4169 tft.fillCircle(posX + 8, posY - 5, 2, BLACK); 4170 // draw sad mouth 4171 tft.drawFastHLine(posX - 11, posY + 10, 3, BLACK); 4172 tft.drawFastHLine(posX + 9, posY + 10, 3, BLACK); 4173 tft.drawFastHLine(posX - 11, posY + 9, 3, BLACK); 4174 tft.drawFastHLine(posX + 9, posY + 9, 3, BLACK); 4175 tft.drawFastHLine(posX - 10, posY + 8, 3, BLACK); 4176 tft.drawFastHLine(posX + 8, posY + 8, 3, BLACK); 4177 tft.drawFastHLine(posX - 10, posY + 7, 3, BLACK); 4178 tft.drawFastHLine(posX + 8, posY + 7, 3, BLACK); 4179 tft.drawFastHLine(posX - 8, posY + 6, 3, BLACK); 4180 tft.drawFastHLine(posX + 6, posY + 6, 3, BLACK); 4181 tft.drawFastHLine(posX - 8, posY + 5, 3, BLACK); 4182 tft.drawFastHLine(posX + 6, posY + 5, 3, BLACK); 4183 tft.drawFastHLine(posX - 6, posY + 4, 3, BLACK); 4184 tft.drawFastHLine(posX + 4, posY + 4, 3, BLACK); 4185 tft.drawFastHLine(posX - 6, posY + 3, 13, BLACK); 4186 tft.drawFastHLine(posX - 4, posY + 2, 9, BLACK); 4187} 4188 4189void yellowSmiley(int posX, int posY) 4190{ 4191 // draw smiley 4192 tft.fillCircle(posX, posY, 17, YELLOW); 4193 //draw eyes 4194 tft.fillCircle(posX - 8, posY - 5, 2, BLACK); 4195 tft.fillCircle(posX + 8, posY - 5, 2, BLACK); 4196 // draw straight mouth 4197 tft.drawFastHLine(19, 111, 19, BLACK); 4198 tft.drawFastHLine(19, 112, 19, BLACK); 4199 4200} 4201 4202void greenSmiley(int posX, int posY) 4203{ 4204 // draw smiley 4205 tft.fillCircle(posX, posY, 17, GREEN); 4206 //draw eyes 4207 tft.fillCircle(posX - 8, posY - 5, 2, BLACK); 4208 tft.fillCircle(posX + 8, posY - 5, 2, BLACK); 4209 // draw smiley mouth 4210 tft.drawFastHLine(posX - 11, posY + 2 , 3, BLACK); 4211 tft.drawFastHLine(posX + 9, posY + 2 , 3, BLACK); 4212 tft.drawFastHLine(posX - 11, posY + 3 , 3, BLACK); 4213 tft.drawFastHLine(posX + 9, posY + 3 , 3, BLACK); 4214 tft.drawFastHLine(posX - 10, posY + 4 , 3, BLACK); 4215 tft.drawFastHLine(posX + 8, posY + 4 , 3, BLACK); 4216 tft.drawFastHLine(posX - 10, posY + 5 , 3, BLACK); 4217 tft.drawFastHLine(posX + 8, posY + 5 , 3, BLACK); 4218 tft.drawFastHLine(posX - 8, posY + 6 , 3, BLACK); 4219 tft.drawFastHLine(posX + 6, posY + 6 , 3, BLACK); 4220 tft.drawFastHLine(posX - 8, posY + 7 , 3, BLACK); 4221 tft.drawFastHLine(posX + 6, posY + 7 , 3, BLACK); 4222 tft.drawFastHLine(posX - 6, posY + 8 , 3, BLACK); 4223 tft.drawFastHLine(posX + 4, posY + 8 , 3, BLACK); 4224 tft.drawFastHLine(posX - 6, posY + 9 , 13, BLACK); 4225 tft.drawFastHLine(posX - 4, posY + 10, 9, BLACK); 4226 4227} 4228 4229/*************************************************************************************************************************************************** 4230 4231 4232 4233 DRAW PLUS MINUS 4234 4235 4236 4237 4238****************************************************************************************************************************************************/ 4239void drawSign(int posX, int posY, int sign) 4240{ 4241 // draw PLUS or MINUS sign compatible with font nr 6 4242 if (sign == 1) 4243 { 4244 // draw PLUS sign 4245 tft.drawFastHLine(posX, posY + 6, 15, GREEN); 4246 tft.drawFastHLine(posX, posY + 7, 15, GREEN); 4247 tft.drawFastHLine(posX, posY + 8, 15, GREEN); 4248 //tft.drawFastHLine(posX, posY + 9, 16, GREEN); 4249 4250 tft.drawFastVLine(posX + 6, posY, 15, GREEN); 4251 tft.drawFastVLine(posX + 7, posY, 15, GREEN); 4252 tft.drawFastVLine(posX + 8, posY, 15, GREEN); 4253 //tft.drawFastVLine(posX + 9, posY, 16, GREEN); 4254 } 4255 else if (sign == 0) 4256 { 4257 // draw MINUS sign 4258 tft.drawFastHLine(posX, posY + 6, 15, RED); 4259 tft.drawFastHLine(posX, posY + 7, 15, RED); 4260 tft.drawFastHLine(posX, posY + 8, 15, RED); 4261 //tft.drawFastHLine(posX, posY + 9, 16, RED); 4262 } 4263 else if (sign == 9) 4264 { 4265 // CLEAR sign 4266 tft.fillRect(posX, posY, 15, 15, BLACK); 4267 } 4268 4269} 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300/*************************************************************************************************************************************************** 4301 4302 ###### ## ## ###### ###### ## ## ## ## ## ## ###### ##### ###### ###### ## ## 4303 ## ### ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 4304 ## ### ## ## ## ## ## ## ## ### ### ## ## ## ## ## #### 4305 ## ## # ## ## ## ####### ## ## ## # ## ## ## ## ## ## ## 4306 ## ## # ## ## ## ## ## ## ## ## # ## ## ## ## ## ## ## 4307 ## ## ### ## ## ## ## ## ## ## ## ## ## ## ## ## ## 4308 ###### ## ## ###### ## ## ## ##### ## ## ###### ##### ###### ## ## 4309 4310****************************************************************************************************************************************************/ 4311void initHumiditySensor() 4312{ 4313 if (!htu21df.begin()) 4314 { 4315 Serial.println("Couldn't find sensor!"); 4316 } 4317} 4318 4319/*************************************************************************************************************************************************** 4320 4321 ###### ## ## ###### ###### ###### ## ###### ### ##### ####### ## ## ##### ### ###### 4322 ## ### ## ## ## ## ## ## ## ## ## ## ## ## ## ### ## ## ## ## ## ## ## 4323 ## ### ## ## ## ## ## #### ## ## ## ## ## ## ### ## ## ## ## ## ## 4324 ## ## # ## ## ## ###### ## # ###### ## ## ##### ##### ## # ## ##### ## ## ###### 4325 ## ## # ## ## ## ## ## ###### ## ## ## ## ## ## ## # ## ## ## ## ## ## 4326 ## ## ### ## ## ## ## ## # ## ## ## ## ## ## ## ## ### ## ## ## ## ## ## 4327 ###### ## ## ###### ## ###### ### ## ## ## ### ##### ####### ## ## ##### ### ## ## 4328 4329****************************************************************************************************************************************************/ 4330void initBaroSensor() 4331{ 4332 // Initialise the pressure sensor 4333 if (!bmp183.begin()) 4334 { 4335 /* There was a problem detecting the BMP183*/ 4336 digitalWrite(ERRORLED, HIGH); 4337 } 4338} 4339 4340/*************************************************************************************************************************************************** 4341 4342 ###### ## ## ###### ###### ###### ####### ###### 4343 ## ### ## ## ## ## ## ## 4344 ## ### ## ## ## ## ## ## 4345 ## ## # ## ## ## ## ##### ## 4346 ## ## # ## ## ## ## ## ## 4347 ## ## ### ## ## ## ## ## 4348 ###### ## ## ###### ## ## ## ## 4349 4350****************************************************************************************************************************************************/ 4351void initTFT() 4352{ 4353 /* Our supplier changed the 1.8" display slightly after Jan 10, 2012 4354 so that the alignment of the TFT had to be shifted by a few pixels 4355 this just means the init code is slightly different. Check the 4356 color of the tab to see which init code to try. If the display is 4357 cut off or has extra 'random' pixels on the top & left, try the 4358 other option! 4359 If you are seeing red and green color inversion, use Black Tab 4360 4361 If your TFT's plastic wrap has a Black Tab, use the following:*/ 4362 tft.initR(INITR_BLACKTAB); // initialize a ST7735S chip, black tab 4363 /* If your TFT's plastic wrap has a Red Tab, use the following: 4364 tft.initR(INITR_REDTAB); // initialize a ST7735R chip, red tab 4365 If your TFT's plastic wrap has a Green Tab, use the following: 4366 tft.initR(INITR_GREENTAB); // initialize a ST7735R chip, green tab*/ 4367 tft.setRotation(1); 4368} 4369 4370 4371/*************************************************************************************************************************************************** 4372 4373 #### ## ####### ## ###### ###### ####### ###### 4374 ## ## ## ## ## ## ## ## ## ## 4375 ## ## ## #### ## ## ## ## ## 4376 ## ## ##### ## # ###### ## ##### ## 4377 ## ## ## ###### ## ## ## ## ## 4378 ## ## ## ## ## # ## ## ## ## ## 4379 #### ###### ####### ### ## ## ## ## ## ## 4380 4381****************************************************************************************************************************************************/ 4382void clearTFT() 4383{ 4384 tft.fillScreen(ST7735_BLACK); 4385} 4386 4387 4388 4389/*************************************************************************************************************************************************** 4390 4391 ###### ## ## ###### ###### ## ## ## ## ## ##### ####### ## ## ##### ### ###### 4392 ## ### ## ## ## ## ## ## ## ## ## ## ## ### ## ## ## ## ## ## ## 4393 ## ### ## ## ## ## ## ## #### ## ## ### ## ## ## ## ## ## 4394 ## ## # ## ## ## ## ## ## ## ##### ##### ## # ## ##### ## ## ###### 4395 ## ## # ## ## ## ## ## ## #### ## ## ## # ## ## ## ## ## ## 4396 ## ## ### ## ## ## ## ## ## ## ## ## ## ## ### ## ## ## ## ## ## 4397 ###### ## ## ###### ## ###### ##### ## ## ##### ####### ## ## ##### ### ## ## 4398 4399****************************************************************************************************************************************************/ 4400void initLuxSensor() 4401{ 4402 Wire.beginTransmission(BH1750_ADDRESS); 4403 Wire.write(0x10); // 1 [lux] resolution 4404 Wire.endTransmission(); 4405} 4406 4407/*************************************************************************************************************************************************** 4408 ###### 4409 ###### ## ## ###### ###### ## ## ##### ####### #### ##### ###### ##### ###### ## 4410 ## ### ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 4411 ## ### ## ## ## ## ## ## ## ## ## ## ## ## ## ## 4412 ## ## # ## ## ## ## ##### ##### ## ## ## ## ##### ###### ## 4413 ## ## # ## ## ## ## ## ## ## ### ## ## ## ## ## ## 4414 ## ## ### ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 4415 ###### ## ## ###### ## ## ##### ####### ##### ##### ###### ##### ## ###### 4416 4417 4418****************************************************************************************************************************************************/ 4419 4420// initialize 7 sgement display and set brightness level 4421void init7SegDisplay() 4422{ 4423 maxim.shutdown(TIMEDISPLAY, false); // Maxim 7219 display display wake up 4424 maxim.clearDisplay(TIMEDISPLAY); // clear display 4425 maxim.setIntensity(TIMEDISPLAY, brightnessTimeDisplay); // set brightness level 4426 4427 maxim.shutdown(DATEDISPLAY, false); // Maxim 7219 display display wake up 4428 maxim.clearDisplay(DATEDISPLAY); // clear display 4429 maxim.setIntensity(DATEDISPLAY, brightnessDateDisplay); // set brightness level 4430 4431 maxim.shutdown(SECONDSDISPLAY, false); // Maxim 7219 display display wake up 4432 maxim.clearDisplay(SECONDSDISPLAY); // clear display 4433 maxim.setIntensity(SECONDSDISPLAY, brightnessSecondsRing); // set brightness level 4434 4435 //DEBUG 4436 //maxim.shutdown(DEBUGDISPLAY, false); // Maxim 7219 display display wake up 4437 //maxim.clearDisplay(DEBUGDISPLAY); // clear display 4438 //maxim.setIntensity(DEBUGDISPLAY, DEBUGDISPLAYBRIGHTNESS); // set brightness level 4439} 4440 4441/*************************************************************************************************************************************************** 4442 4443 #### ## ####### ## ###### ###### ###### ## ## ####### ##### ###### ##### ###### ## 4444 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 4445 ## ## ## #### ## ## ## ## ### ### ## ## ## ## ## ## ## ## 4446 ## ## ##### ## # ###### ## ## ## # ## ##### ## ## ## ##### ###### ## 4447 ## ## ## ###### ## ## ## ## ## # ## ## ## ## ## ## ## ## 4448 ## ## ## ## ## # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 4449 #### ###### ####### ### ## ## ## ## ###### ## ## ####### ##### ###### ##### ## ###### ## 4450 4451****************************************************************************************************************************************************/ 4452// clears the 7 segemnt display 4453void clearTimeDisplay() 4454{ 4455 maxim.clearDisplay(TIMEDISPLAY); 4456} 4457 4458/*************************************************************************************************************************************************** 4459 4460 #### ## ####### ## ###### ##### ## ###### ####### ##### ###### ##### ###### ## 4461 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 4462 ## ## ## #### ## ## ## ## #### ## ## ## ## ## ## ## ## ## 4463 ## ## ##### ## # ###### ## ## ## # ## ##### ## ## ## ##### ###### ## 4464 ## ## ## ###### ## ## ## ## ###### ## ## ## ## ## ## ## ## 4465 ## ## ## ## ## # ## ## ## ## ## # ## ## ## ## ## ## ## ## ## ## 4466 #### ###### ####### ### ## ## ## ##### ### ## ## ####### ##### ###### ##### ## ###### ## 4467 4468****************************************************************************************************************************************************/ 4469// clears the 7 segemnt display 4470void clearDateDisplay() 4471{ 4472 maxim.clearDisplay(DATEDISPLAY); 4473} 4474 4475/*************************************************************************************************************************************************** 4476 4477 #### ## ####### ## ###### ##### ####### #### ##### ###### ##### ###### ## 4478 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 4479 ## ## ## #### ## ## ## ## ## ## ## ## ## ## ## ## 4480 ## ## ##### ## # ###### ##### ##### ## ## ## ## ##### ###### ## 4481 ## ## ## ###### ## ## ## ## ## ## ## ## ## ## ## 4482 ## ## ## ## ## # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 4483 #### ###### ####### ### ## ## ## ##### ####### #### ## ##### ###### ##### ## ###### ## 4484 4485****************************************************************************************************************************************************/ 4486// clears the 7 segemnt display 4487void clearSecondsDisplay() 4488{ 4489 maxim.clearDisplay(SECONDSDISPLAY); 4490} 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509/*************************************************************************************************************************************************** 4510 4511 ###### ###### ###### #### ## ## ###### ## ## ####### ##### ##### ## ##### #### 4512 ## ## ## ## ## ## ## ## ## ## ### ## ## ## ## ## ## ## ## ## ## 4513 ## ## ## ## ## ## ## ## ## ### ## ## ## ## #### ## ## ## 4514 ###### ###### ## ## ####### ## ## # ## ##### ##### ##### ## # ## ## ## 4515 ## ## ## ## ## ## ### ## ## ## ## # ## ## ## ## ###### ## ## ## ## 4516 ## ## ## ## ## ## ## ## ## ## ## ### ## ## ## ## ## ## # ## ## ## ## 4517 ###### ## ## ###### ##### ## ## ## ## ## ####### ##### ##### ### ## ##### #### 4518 4519****************************************************************************************************************************************************/ 4520// check ambient light and adjust the display brightness 4521void brightnessAdj() 4522{ 4523 analogWrite(TFT_LIGHT, brightnessLcdBacklight); 4524 analogWrite(MARKERS_HOURS, brightnessHourMarkers); 4525 analogWrite(MARKERS_MINUTES, brightnessMinuteMarkers); 4526 4527 //if(second()%3 == 0) 4528 //{ 4529 // byte i=0; 4530 // Wire.beginTransmission(BH1750_ADDRESS); 4531 // Wire.requestFrom(BH1750_ADDRESS, 2); 4532 // while(Wire.available()) 4533 // { 4534 // buff[i] = Wire.read(); 4535 // i++; 4536 // } 4537 // Wire.endTransmission(); 4538 // 4539 // float valf=0; 4540 // if(i == 2) 4541 // { 4542 // valf = ( (buff[0]<<8) | buff[1] ) / 1.2; 4543 // maxim.setIntensity(TIMEDISPLAY, map(valf, 0, 300, 0, 15)); // set brightness level of time display 4544 // maxim.setIntensity(SECONDSDISPLAY, map(valf, 0, 300, 0, 15)); // set brightness level of seconds LED's 4545 // maxim.setIntensity(DATEDISPLAY, map(valf, 0, 300, 0, 15)); // set brightness level of seconds LED's 4546 // } 4547 //}// if(second()%3 == 0) 4548} 4549 4550 4551 4552/*************************************************************************************************************************************************** 4553 #### 4554 ###### ####### ###### ## ## ###### ## ## ## ## ###### ###### ####### ## ## ## ## ####### ## ## ## ## 4555 ## ## ## ## ## ## ## ## ### ## ## ## ## ## ## ## ## ## ## ## ## ### ## ## ## 4556 ## ## ## ## ## ## ## ## ### ## ## ## ## ## ## ## ## ## ### ### ## ### ## ## ## 4557 ###### ##### ## ## ## ###### ## # ## ## ###### ###### ##### ## ## ## # ## ##### ## # ## ## ## 4558 ## ## ## ## ## ## ## ## ## # ## ## ## ## ## ## ## ## ## # ## ## ## # ## ## ## 4559 ## ## ## ## ## ## ## ## ## ### ## ## ## ## ## ### ## ## ## ## ## ### ## ## 4560 ## ## ####### ## ##### ## ## ## ## ###### ## ## ## ####### ### ## ## ## ####### ## ## ##### 4561 4562****************************************************************************************************************************************************/ 4563// return to previous menu 4564void returnToPreviousMenu() 4565{ 4566 switch (previousMenu) 4567 { 4568 case 0: 4569 currState = STATE_MAIN; 4570 break; 4571 case 1: 4572 currState = STATE_TEMP_DISPLAY; 4573 break; 4574 case 2: 4575 currState = STATE_TIME_DETAIL; 4576 break; 4577 case 3: 4578 currState = STATE_BAROGRAPH; 4579 break; 4580 case 4: 4581 currState = STATE_BAROGRAPH_TREND; 4582 break; 4583 case 5: 4584 currState = STATE_BAROGRAPH_TREND; 4585 break; 4586 } 4587} 4588 4589 4590 4591/*************************************************************************************************************************************************** 4592 4593 #### ### ## ## ## ## ####### ###### ##### ###### ### ## ## ##### 4594 ## ## ## ## ### ## ## ## ## ## ## ## ## ## ## ## ### ## ## ## 4595 ## ## ## ### ## ## ## ## ## ## ## ## ## ## ### ## ## 4596 ## ## ## ## # ## ## ## ##### ###### ##### ## ## ## ## # ## ##### 4597 ## ## ## ## # ## ## ## ## ## ## ## ## ## ## ## # ## ## 4598 ## ## ## ## ## ### ### ## ## ## ## ## ## ## ## ## ### ## ## 4599 #### ### ## ## ### ####### ## ## ##### ###### ### ## ## ##### 4600 4601****************************************************************************************************************************************************/ 4602// Convert normal decimal numbers to binary coded decimal 4603byte dec2Bcd(byte val) 4604{ 4605 return ( (val / 10 * 16) + (val % 10) ); 4606} 4607 4608//---------------------------------------------------------------------------------------------------------- 4609// Convert binary coded decimal to decimal 4610byte bcd2Dec(byte val) 4611{ 4612 return ( (val / 16 * 10) + (val % 16) ); 4613} 4614 4615 4616 4617/*************************************************************************************************************************************************** 4618 4619 #### ## ## #### ## ## ####### ####### ## ## ## ## ###### 4620 ## ## ## ## ## ## ## ## ## ## ## ## ### ## ## ## 4621 ## #### ## ## ## # ## ## ## ## ## ### ## ## ## 4622 ## ## # ## ## ## # ## ##### ##### #### ## # ## ###### 4623 ## ###### ## ## ## # ## ## ## ## ## ## # ## ## ## 4624 ## ## ## # ## ## ## ### ### ## ## ## ## ## ### ## ## 4625 #### ### ## ###### #### ## ## ####### ####### ## ## ## ## ## ## 4626 4627****************************************************************************************************************************************************/ 4628 4629 4630 4631/* 4632 Code from: http://forum.arduino.cc/index.php/topic,44476.0.html 4633 4634 you need to declare two global variables: 4635 Code: 4636 short dayNumber; //Returns the number of day in the year 4637 short weekNumber; //Returns the number of the week in the year 4638 4639 and this is how you need to call the function in your loop: 4640 Code: 4641 dayWeekNumber(year(),month(),day(),weekday()); 4642 4643 Take into account that i use TIME library in my sketch, so how you call to year, month, day and day of week could change for other libraries. 4644 4645 and this is an example of how to call the function and show the results: 4646 Code: 4647 dayWeekNumber(year(),month(),day(),weekday()); 4648 Serial.print("Day #"); 4649 Serial.print(dayNumber); 4650 Serial.print(" at week # "); 4651 Serial.print(weekNumber); 4652 Serial.print(" of "); 4653 Serial.println(year()); 4654 4655 Be aware than in the function, there is a problematic line: 4656 Code: 4657 WN = (DN-7+10)/7; 4658 This is because in the library the week starts on Sunday (0), however, in the ISO standard, 4659 week start on monday (1), and sunday is the last day (7). For that reason, i included this especial case in the code. 4660*/ 4661int dayWeekNumber(int y, int m, int d, int w) 4662{ 4663 // Number of days at the beginning of the month in a (not leap) year. 4664 int days[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; 4665 4666 //Start to calculate the number of day 4667 if (m == 1 || m == 2) { 4668 //for any type of year, it calculate the number of days for January or february 4669 dayNumber = days[(m - 1)] + d; 4670 } // if 4671 // Now, try to calculate for the other months 4672 else if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0) { //those are the conditions to have a leap year 4673 // if leap year, calculate in the same way but increasing one day 4674 dayNumber = days[(m - 1)] + d + 1; 4675 } // else if 4676 else 4677 { 4678 //if not a leap year, calculate in the normal way, such as January or February 4679 dayNumber = days[(m - 1)] + d; 4680 } // else 4681 // Now start to calculate Week number 4682 if (w == 1) { 4683 //if it is sunday (time library returns 1) 4684 weekNumber = (dayNumber - 7 + 10) / 7; 4685 } // if 4686 else 4687 { 4688 // for the other days of week 4689 weekNumber = (dayNumber - (w - 1) + 10) / 7; 4690 } // else 4691 return weekNumber; 4692} 4693 4694/*************************************************************************************************************************************************** 4695 4696 #### ## ## #### ## ####### ## ###### ## ## ####### ## ###### 4697 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 4698 ## #### ## ## ## ## #### ## ## #### ## #### ## ## 4699 ## ## # ## ## ## ##### ## # ###### ## ##### ## # ###### 4700 ## ###### ## ## ## ## ###### ## ## ## ###### ## ## 4701 ## ## ## # ## ## ## ## ## ## # ## ## ## ## # ## ## 4702 #### ### ## ###### #### ###### ####### ### ## ## ## ####### ### ## ## ## 4703 4704****************************************************************************************************************************************************/ 4705 4706/***** 4707 Purpose: Determine if a given year is a leap year 4708 Parameters: int year // The year to test 4709 Return value: int // '1' if the year is a leap year, '0'otherwise 4710 *****/ 4711int calculateLeapYear() 4712{ 4713 if ( (year() % 4 == 0 && year() % 100 != 0) || (year() % 400 == 0) ) 4714 { 4715 return 1; 4716 } 4717 else 4718 { 4719 return 0; 4720 } 4721} 4722 4723/*************************************************************************************************************************************************** 4724 4725 #### ## ## #### #### ### ## ## ####### ### ###### ###### ## ## ## ## 4726 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 4727 ## #### ## ## ## ## ## ### ### ## ## ## ## ## ## ## ## ## ## 4728 ## ## # ## ## ## ## ## ## # ## ##### ## ## ###### ## ## ## ## ## 4729 ## ###### ## ## ## ## ## ## # ## ## ## ## ## ## ## ## ## ## ## 4730 ## ## ## # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ### ## 4731 #### ### ## ###### #### #### ### ## ## ## ### ## ## ## ###### ### ###### 4732 4733****************************************************************************************************************************************************/ 4734void calculateClimateComfort() 4735{ 4736 //calculation of relation between humidity and temperature, resulting in indication of 'comfort level' 4737 // RED = oncomfortable humid or dry, YELLOW = still comfortable, GREEN = comfortable 4738 4739 // tempCelcius is 3 digits eg 215, we need to divide by 10 to get temperature. 4740 int temp = tempCelcius / 10; 4741 4742 if (humidity < 20) 4743 { 4744 climateComfort = ccRED; 4745 } 4746 4747 else if ( (humidity / 10) < 30) 4748 { 4749 if (temp < 20) 4750 { 4751 climateComfort = ccRED; 4752 } 4753 else if (temp >= 20 && temp < 26) 4754 { 4755 climateComfort = ccYELLOW; 4756 } 4757 else if (temp >= 26) 4758 { 4759 climateComfort = ccRED; 4760 } 4761 }// else if( (humidity / 10) < 30) 4762 4763 else if ( (humidity / 10) < 40) 4764 { 4765 if (temp < 20) 4766 { 4767 climateComfort = ccRED; 4768 } 4769 else if (temp >= 20) 4770 { 4771 climateComfort = ccYELLOW; 4772 } 4773 }// else if( (humidity / 10) < 40) 4774 4775 else if ( (humidity / 10) < 50) 4776 { 4777 if (temp < 20) 4778 { 4779 climateComfort = ccYELLOW; 4780 } 4781 else if (temp >= 20 && temp < 24) 4782 { 4783 climateComfort = ccGREEN; 4784 } 4785 else if (temp >= 24) 4786 { 4787 climateComfort = ccYELLOW; 4788 } 4789 }// else if( (humidity / 10) < 50) 4790 4791 else if ( (humidity / 10) < 60) 4792 { 4793 if (temp < 20) 4794 { 4795 climateComfort = ccYELLOW; 4796 } 4797 else if (temp >= 20 && temp < 24) 4798 { 4799 climateComfort = ccGREEN; 4800 } 4801 else if (temp >= 24 && temp < 26) 4802 { 4803 climateComfort = ccYELLOW; 4804 } 4805 else if (temp >= 26) 4806 { 4807 climateComfort = ccRED; 4808 } 4809 }// else if( (humidity / 10) < 60) 4810 4811 else if ( (humidity / 10) < 70) 4812 { 4813 if (temp < 24) 4814 { 4815 climateComfort = ccGREEN; 4816 } 4817 else if (temp >= 24 && temp < 26) 4818 { 4819 climateComfort = ccYELLOW; 4820 } 4821 else if (temp >= 26) 4822 { 4823 climateComfort = ccRED; 4824 } 4825 }// else if( (humidity / 10) < 70) 4826 4827 else if ( (humidity / 10) < 80) 4828 { 4829 if (temp < 22) 4830 { 4831 climateComfort = ccYELLOW; 4832 } 4833 else if (temp >= 22) 4834 { 4835 climateComfort = ccRED; 4836 } 4837 }// else if( (humidity / 10) < 80) 4838 4839 else if ( (humidity / 10) >= 90) 4840 { 4841 climateComfort = ccRED; 4842 } 4843 4844}// void 4845 4846/*************************************************************************************************************************************************** 4847 4848 4849 CALC MOON PHASE 4850 4851 4852 4853****************************************************************************************************************************************************/ 4854/* This is a function you can use in your Arduino sketches for calculating the current lunar phase. 4855 The function, GetPhase, takes three parameters: the year, the month and the day. 4856 Note that the year must be 4 digits. 4857 The function returns a float type containing the percentage of illumination 4858 (0 for new, .25 for crescent, .5 for quarter, .75 for gibbous and 1 for full). 4859 4860 Following are the functions GetPhase and MyNormalize (which is called by GetPhase) 4861*/ 4862 4863float GetPhase(int nYear, int nMonth, int nDay) // calculate the current phase of the moon 4864{ 4865 float phase; 4866 double AG, IP; 4867 long YY, MM, K1, K2, K3, JD; 4868 YY = nYear - floor((12 - nMonth) / 10); 4869 MM = nMonth + 9; 4870 if (MM >= 12) 4871 { 4872 MM = MM - 12; 4873 } 4874 K1 = floor(365.25 * (YY + 4712)); 4875 K2 = floor(30.6 * MM + 0.5); 4876 K3 = floor(floor((YY / 100) + 49) * 0.75) - 38; 4877 JD = K1 + K2 + nDay + 59; 4878 if (JD > 2299160) 4879 { 4880 JD = JD - K3; 4881 } 4882 IP = MyNormalize((JD - 2451550.1) / 29.530588853); 4883 AG = IP * 29.53; 4884 phase = 0; 4885 if ((AG < 1.84566) && (phase == 0)) 4886 { 4887 phase = 0; //new; 0% illuminated 4888 } 4889 if ((AG < 5.53699) && (phase == 0)) 4890 { 4891 phase = .25; //Waxing crescent; 25% illuminated 4892 } 4893 if ((AG < 9.922831) && (phase == 0)) 4894 { 4895 phase = .50; //First quarter; 50% illuminated 4896 } 4897 if ((AG < 12.91963) && (phase == 0)) 4898 { 4899 phase = .75; //Waxing gibbous; 75% illuminated 4900 } 4901 if ((AG < 16.61096) && (phase == 0)) 4902 { 4903 phase = 1; //Full; 100% illuminated 4904 } 4905 if ((AG < 20.30228) && (phase == 0)) 4906 { 4907 phase = .75; //Waning gibbous; 75% illuminated 4908 } 4909 if ((AG < 23.99361) && (phase == 0)) 4910 { 4911 phase = .50; //Last quarter; 50% illuminated 4912 } 4913 if ((AG < 27.68493) && (phase == 0)) 4914 { 4915 phase = .25; //Waning crescent; 25% illuminated 4916 } 4917 if (phase == 0) 4918 { 4919 phase = 0; //default to new; 0% illuminated 4920 } 4921 return phase; 4922} 4923 4924double MyNormalize(double v) 4925{ 4926 v = v - floor(v); 4927 if (v < 0) 4928 v = v + 1; 4929 return v; 4930} 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947/*************************************************************************************************************************************************** 4948 4949 ##### ###### ##### ###### ## ## ## ## ##### ###### ## ###### ####### 4950 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## 4951 ## ## ## ## ## ## ## #### #### ## ## #### ## ## 4952 ## ## ## ##### ###### ## ## # ## ##### ## ## # ## ##### 4953 ## ## ## ## ## ## ###### ## ## ## ###### ## ## 4954 ## ## ## ## ## ## ## ## # ## ## ## ## ## # ## ## 4955 ##### ###### ##### ## ###### ### ## ## ##### ## ### ## ## ####### 4956 4957****************************************************************************************************************************************************/ 4958void displayState() 4959{ 4960 if (millis() - timer1 > 1000) 4961 { 4962 timer1 = millis(); 4963 4964 maxim.setChar(DATEDISPLAY, 7, 'P', true); 4965 maxim.setChar(DATEDISPLAY, 6, previousMenu / 10, false); 4966 maxim.setChar(DATEDISPLAY, 5, previousMenu % 10, false); 4967 maxim.setChar(DATEDISPLAY, 4, ' ', false); 4968 maxim.setChar(DATEDISPLAY, 3, currState / 10, false); 4969 maxim.setChar(DATEDISPLAY, 2, currState % 10, false); 4970 maxim.setChar(DATEDISPLAY, 1, ' ', false); 4971 maxim.setChar(DATEDISPLAY, 0, userAction, false); 4972 } 4973} 4974 4975 4976 4977// debug 4978void readArray() 4979{ 4980 Serial << endl << endl << "Inhoud van barometerData array" << endl; 4981 // start address: barometerData[0] = 100, barometerData[129] = address 358 4982 for (int i = 0; i <= 130; i++) 4983 { 4984 Serial << "Array nr.: " << i << "\ Value : " << barometerData[i] << endl; 4985 } 4986} 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011/*************************************************************************************************************************************************** 5012 5013 ###### ####### ####### ####### ###### ####### ## ## #### ####### 5014 ## ## ## ## ## ## ## ## ### ## ## ## ## 5015 ## ## ## ## ## ## ## ## ### ## ## ## 5016 ###### ##### ##### ##### ###### ##### ## # ## ## ##### 5017 ## ## ## ## ## ## ## ## ## # ## ## ## 5018 ## ## ## ## ## ## ## ## ## ### ## ## ## 5019 ## ## ####### ## ####### ## ## ####### ## ## #### ####### 5020 5021 5022****************************************************************************************************************************************************/ 5023 5024/*Ledcontrol library: 5025 5026 maxim.clearDisplay(int addr) ..................................... clears the selected display 5027 maxim.shutdown(int addr, boolean) ................................ wake up the MAX72XX from power-saving mode (true = sleep, false = awake) 5028 maxim.setIntensity(int addr, value) .............................. set a medium brightness for the Leds (0=min - 15=max) 5029 maxim.setLed(int addr, int row, int col, boolean state) .......... switch on the led in row, column. remember that indices start at 0! 5030 maxim.setRow(int addr, int row, byte value) ...................... this function takes 3 arguments. example: maxim.setRow(0,2,B10110000); 5031 maxim.setColumn(int addr, int col, byte value) ................... this function takes 3 arguments. example: maxim.setColumn(0,5,B00001111); 5032 maxim.setDigit(int addr, int digit, byte value, boolean dp) ....... this function takes an argument of type byte and prints the corresponding digit on the specified column. 5033 The range of valid values runs from 0..15. All values between 0..9 are printed as digits, 5034 values between 10..15 are printed as their hexadecimal equivalent 5035 maxim.setChar(int addr, int digit, char value, boolean dp) ....... will display: 0 1 2 3 4 5 6 7 8 9 A B C D E F H L P; - . , _ <SPACE> (the blank or space char) 5036 5037 pin 12/7 is connected to the DataIn 5038 pin 11/6 is connected to the CLK 5039 pin 10/5 is connected to CS/LOAD 5040 5041***** Please set the number of devices you have ***** 5042 But the maximum default of 8 MAX72XX wil also work. 5043 LedConrol(DATAIN, CLOCK, CS/LOAD, NUMBER OF MAXIM CHIPS) 5044 5045 5046 5047 //STREAMING.h .................................................... http://arduiniana.org/libraries/streaming/ 5048 5049 New users sometimes wonder why the “Arduino language” doesn’t provide the kind 5050 of concatenation or streaming operations they have become accustomed to in Java/VB/C#/C++, etc. 5051 lcd << "GPS #" << gpsno << " date: " << day << "-" << month << "-" << year << endl; 5052 This library works for any class that derives from Print: 5053 // Serial << "Counter: " << counter; 5054 lcd << "Temp: " << t.get_temperature() << " degrees"; 5055 my_pstring << "Hi Mom!" << endl; 5056 With the new library you can also use formatting manipulators like this: 5057 // Serial << "Byte value: " << _HEX(b) << endl; 5058 lcd << "The key pressed was " << _BYTE(c) << endl; 5059 This syntax is familiar to many, is easy to read and learn, and, importantly, *** consumes no resources *** 5060 (Because the operator functions are essentially just inline aliases for their print() counterparts, 5061 no sketch gets larger or consumes more RAM as a result of their inclusion.) 5062 5063 5064 5065 5066 5067 5068 /*------------------------------------------------------------------------ 5069 /*-------{ Adafruit TFT functions }--------------------------------------- 5070 /*------------------------------------------------------------------------ 5071 5072 Clearing or filling the screen 5073 The fillScreen() function will set the entire display to a given color, erasing any existing content: 5074 void fillScreen(uint16_t color); 5075 5076 Characters 5077 There are two basic string drawing procedures for adding text. 5078 The first is just for a single character. 5079 You can place this character at any location and with any color. 5080 There’s only one font (to save on space) and it’s meant to be 5x8 pixels, 5081 but an optional size parameter can be passed which scales the font by this factor 5082 (e.g. size=2 will render the text at 10x16 pixels per character). 5083 It’s a little blocky but having just a single font helps keep the program size down. 5084 void drawChar(uint16_t x, uint16_t y, char c, uint16_t color, uint16_t bg, uint8_t size); 5085 5086 Text 5087 Text is very flexible but operates a bit differently. 5088 Instead of one procedure, the text size, color and position are set up 5089 in separate functions and then the print() function is used 5090 — this makes it easy and provides all of the same string and number 5091 formatting capabilities of the familiar Serial.print() function! 5092 void setCursor(uint16_t x0, uint16_t y0); 5093 void setTextColor(uint16_t color); 5094 void setTextColor(uint16_t color, uint16_t backgroundcolor); void setTextSize(uint8_t size); 5095 void setTextWrap(boolean w); 5096 Begin with setCursor(x, y), which will place the top left corner of the text wherever you please. 5097 Initially this is set to (0,0) (the top-left corner of the screen). 5098 Then set the text color with setTextColor(color) — by default this is white. 5099 Text is normally drawn “clear” — the open parts of each character show the original background contents, 5100 but if you want the text to block out what’s underneath, a background color can be specified 5101 as an optional second parameter tosetTextColor(). Finally, setTextSize(size) will multiply the scale 5102 of the text by a given integer factor. 5103 5104 5105 Drawing pixels (points) 5106 First up is the most basic pixel pusher. 5107 You can call this with X, Y coordinates and a color and it will make a single dot: 5108 void drawPixel(uint16_t x, uint16_t y, uint16_t color); 5109 5110 Drawing lines 5111 You can also draw lines, with a starting and end point and color: 5112 void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color); 5113 5114 For horizontal or vertical lines, there are optimized line-drawing functions that avoid the angular calculations: 5115 void drawFastVLine(uint16_t x0, uint16_t y0, uint16_t length, uint16_t color); 5116 void drawFastHLine(uin86_t x0, uin86_t y0, uint8_t length, uint16_t color); 5117 5118 Rectangles 5119 Next up, rectangles and squares can be drawn and filled using the following procedures. 5120 Each accepts an X, Y pair for the top-left corner of the rectangle, 5121 a width and height (in pixels), and a color. 5122 drawRect() renders just the frame (outline) of the rectangle — the interior is unaffected — 5123 while fillRect() fills the entire area with a given color: 5124 void drawRect(uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, uint16_t color); 5125 void fillRect(uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, uint16_t color); 5126 5127 Circles 5128 Likewise, for circles, you can draw and fill. 5129 Each function accepts an X, Y pair for the center point, a radius in pixels, and a color: 5130 void drawCircle(uint16_t x0, uint16_t y0, uint16_t r, uint16_t color); 5131 void fillCircle(uint16_t x0, uint16_t y0, uint16_t r, uint16_t color); 5132 5133 5134 Rounded rectangles 5135 For rectangles with rounded corners, both draw and fill functions are again available. 5136 Each begins with an X, Y, width and height (just like normal rectangles), 5137 then there’s a corner radius (in pixels) and finally the color value: 5138 void drawRoundRect(uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, uint16_t radius, uint16_t color); 5139 void fillRoundRect(uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, uint16_t radius, uint16_t color); 5140 5141 Triangles 5142 With triangles, once again there are the draw and fill functions. 5143 Each requires a full seven parameters: the X, Y coordinates for 5144 three corner points defining the triangle, followed by a color: 5145 void drawTriangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color; 5146 void fillTriangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color; 5147 5148 Bitmaps 5149 You can draw small monochrome (single color) bitmaps, good for sprites and other mini- animations or icons: 5150 This issues a contiguous block of bits to the display, where each '1' bit sets the 5151 corresponding pixel to 'color,' while each '0' bit is skipped. x, y is the top-left corner 5152 where the bitmap is drawn, w, h are the width and height in pixels. 5153 The bitmap data must be located in program memory using the PROGMEM directive. 5154 This is a somewhat advanced function and beginners are best advised to come back to this later. 5155 For an introduction, see the Arduino tutorial on PROGMEM usage (http://adafru.it/aMw). 5156 void drawBitmap(int16_t x, int16_t y, uint8_t *bitmap, int16_t w, int16_t h, uint16_t color); 5157 5158 Rotating the Display 5159 You can also rotate your drawing. Note that this will not rotate what you already drew, 5160 but it will change the coordinate system for any new drawing. This can be really handy 5161 if you had to turn your board or display sideways or upside down to fit in a particular enclosure. 5162 In most cases this only needs to be done once, inside setup(). 5163 We can only rotate 0, 90, 180 or 270 degrees - anything else is not possible in hardware 5164 and is too taxing for an Arduino to calculate in software 5165 5166 Screen Reference 5167 If you need to reference the size of the screen (which will change between portrait and landscape modes), 5168 use width() and height(). 5169 uint16_t width(); 5170 uint16_t height(); 5171 Each returns the dimension (in pixels) of the corresponding axis, adjusted for the display’s current rotation setting. 5172 5173 5174 /*------------------------------------------------------------------------ 5175 /*-------{ ClickButton }-------------------------------------------------- 5176 /*------------------------------------------------------------------------ 5177 A simple one-button Arduino library to get short and long clicks, multiple clicks (double click, triple click etc.). Click-and-hold is also possible. 5178 5179 Features: Button clicks, basically :) 5180 Buttons (Or rather the input signal) 5181 Debounced (Default: 20 ms debounce timer) 5182 Current state 5183 Active low (can use the internal pullup-resistor) 5184 Active high 5185 Clicks (IE signal timings) 5186 Short click(s) (Default: Click count within 250 ms) 5187 Long click(s) (Default: Last click is held down for at least 1 second) 5188 Dynamic settings for short/long clicks and debounce timers. 5189 Details (some of them anyway) 5190 Short clicks is simply the number of clicks within a set timelimit (default 250 ms). 5191 5192 Long clicks are clicks where the last click is held down for a "longer" time. As suggested any preceding clicks (if applicable) must be short clicks. (I just thought it would be kind of boring to have lots of long multiple clicks). 5193 5194 Example: a "long double-click" (if there is such a thing) is just a normal double-click where the button is held down at the last click, then it may be released after a time (default 1 second). 5195 Click-and-hold can also be determined, simply by getting a long click and then checking that the button is still held down. 5196 5197 The debounced button state is also available at any time. 5198 5199 Easy to change default timer settings for button debounce, short and long clicks (on-the-fly if you want - not that you'd want to do that all the time, probably). 5200 5201 One "ClickButton" instance copes with only one button, individually. One must instantiate several ClickButton objects if one wants to use more than one button. If you want to combine several buttons, you must do so in your own code. 5202 5203 A multiple buttons example is included (using an array of ClickButton objects). 5204 5205 5206 5207 5208 /*------------------------------------------------------------------------ 5209 /*-------{ DS18B20 init }------------------------------------------------- 5210 /*------------------------------------------------------------------------ 5211 5212 void writeScratchpad(void) 5213 { 5214 5215 5216 5217 // This is done ONCE in setup()