hagakure
Published © GPL3+

Automated Snake Enclosure with Camera

Interactive snake enclosure that is temperature and humidity controlled and uses lat-long to mimic natural light cycles, with an online cam.

IntermediateShowcase (no instructions)14,232
Automated Snake Enclosure with Camera

Things used in this project

Hardware components

Arduino Mega 2560
Arduino Mega 2560
×1
Seeed Studio w5200 Ethernet Shield
×1
DHT22 Temperature Sensor
DHT22 Temperature Sensor
×1
Seeed Studio 2.8 TFT Touch Shield V2.0
×1
Temperature Sensor
Temperature Sensor
×2
SEEED Studio Relay Shield
×2
Pmod RTCC
Digilent Pmod RTCC
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Harold and Kumar w/out IP

Fritzing

Code

Harold and Kumar w/out IP code

C/C++
Arduino
#include <SD.h>
#include <stdint.h>
#include <SeeedTouchScreen.h>
#include <TFTv2.h>
#include <SPI.h>
#include <Time.h>
#include <TimeLib.h>
#include <DHT.h>
#include <DHT_U.h>
#include <OneWire.h>
#include <DS3232RTC.h>
#include <Adafruit_Sensor.h>
#include <TimeLord.h>
#include <Wire.h>
#include "DHT.h"
#include <DallasTemperature.h>
#include <EthernetV2_0.h>
#include "TFTv2.h"
int page;
int firsttimeon = 1;
//time veriables
int daynow;
int monthnow;
int yearnow;
int minutenow;
int hournow;
int tpage;
int npage;
int dnchan;
float const LONGITUDE = -1.41503959;
float const LATITUDE = 8.528874379;
//temp and humid veriables
float humidmin;
float humidminset;
int humidday;
#define DHTPIN 22 // temp/humidity sensor 
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
float hkhr1temp;
float hkhr2temp;
float hkdaytemp;
float hknighttemp;
float ambitempcur;
float ambitempdisp;
float hkdaytempdisp;
float hknighttempdisp;
float humidcur;
float humiddisp;
#define hr1 23
#define hr2 24
OneWire oneWire_hr1(hr1);
OneWire oneWire_hr2(hr2);
DallasTemperature sensor_hr1(&oneWire_hr1);
DallasTemperature sensor_hr2(&oneWire_hr2);
float hr1tempcur;
float hr1tempdisp;
float hr2tempcur;
float hr2tempdisp;
int ambitempday;
int ambitempnight;
float roomtemp;
float roomtempdisp;
//light cycle veriables
int srhour;
int srminute;
int srsecond;
int srhourset;
int srminuteset;
int srhoursetdisp;
int srminutesetdisp;
int srsecondset;
int srday;
int sshour;
int ssminute;
int sssecond;
int sshourset;
int ssminuteset;
int sssecondset;
int ssminutesetdisp;
int sshoursetdisp;
int ssday = 0;
int night;
byte todaysr[] = {0, 0, 0, 0, 0, 0};
byte todayss[] = {0, 0, 0, 0, 0, 0};
byte dlstime[] = {0, 0, hour(), day(), month(), year()};
long timenow;
long timess;
long timesr;
//pin variables
//ambient heat/humidity is pin 22
// heat rock 1 temp is pin 23
// heat rock 2 temp is pin 24
// ds3231rtc SCL is on analog pin A5
// ds3231rtc SDA is on analog pin A4
const int dnlamp = 25;
const int fogger = 26;
const int hrock1 = 27;
const int hrock2 = 28;
const int fan = 29;
const int foggerwater = 31;
const int hlamp = 30;
const int rset = 41;
// sensor quality veriables
int ambithsen;
int hr1sen;
int hr2sen;
int foggersen;
//power on veriables
int dlpwr;
int hlpwr;
int hr1pwr;
int hr2pwr;
int fogpwr;
int fanpwr;
int foggerpwr;
TouchScreen ts = TouchScreen(XP, YP, XM, YM); //init TouchScreen port pins
// file varieables
String myData;
String myDoc;
File myFile;
/*Cat5 wires
  Red Taped ---- Relay Box
  Solid Brown = 5v
  White Brown = Ground
  Solid Green = Pin 7 of always on relay -- Heat Rock 2 Power -- Arduino Pin = 28
  White Green = Pin 6 of always on relay -- Heat Rock 1 Power -- Arduino Pin = 27
  Solid Blue = Pin 5 of always on relay -- Heat Lamp Power -- Arduino Pin = 30
  White Blue = Pin 4 of always on relay -- Day/Night Lights Power -- Arduino Pin = 25
  Solid Orange = Pin 5 of power save relay -- Fogger Power -- Arduino Pin = 26
  White Orange = Pin 4 of power save relay -- Unused
  //
  White Taped ---- Relay Box
  Solid Green = Pin 7 of power save relay -- Fan Relay -- Arduino Pin = 29
  White Green = Unused
  Solid Blue = J1 Open Fan relay
  White Blue = J1 Common Fan relay
  Solid Brown = Unused
  White Brown = Unused
  Solid Orange = 5v
  White Orange = Ground
  //
  Yellow Tape ---- Sensors
  Solid Brown = Fan Power
  White Brown = Fan Ground
  Solid Green = Ambiant Temperature/Humidity Sensor -- Arduino Pin = 22
  White Green = Heat Rock 1 Sensor -- Arduino Pin = 23
  Solid Blue = Heat Rock 2 Sensor -- Arduino Pin = 24
  White Blue = UNUSED
  Solid Orange = 5v
  White Orange = Ground
  //
  Red Yellow Tape ---- Touch Screen
  Solid Brown = Top Right ICSP
  White Brown = Analog 3
  Solid Green = Analog 2
  White Green = Analog 1
  Solid Blue = Analog 0
  White Blue = Reset
  Solid Orange = 5v
  White Orange = Ground
  //
  Red White Tape ---- Touch Screen
  Solid Brown = Digital 7
  White Brown = Digital 6
  Solid Green = Digital 5
  White Green = Bottom Left ICSP
  Solid Blue = Top Left ICSP
  White Blue = Bottom Middle ICSP
  Solid Orange = Top MiddleICSP
  White Orange = Bottom Right ICSP
*/
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 109);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(6113);
#define W5200_CS 10
#define SDCARD_CS 4
//Camera definitions
#define VC0706_PROTOCOL_SIGN       0x56
#define VC0706_Serial2_NUMBER       0x00
#define VC0706_COMMAND_RESET      0x26
#define VC0706_COMMAND_GEN_VERSION    0x11
#define VC0706_COMMAND_TV_OUT_CTRL    0x44
#define VC0706_COMMAND_OSD_ADD_CHAR   0x45
#define VC0706_COMMAND_DOWNSIZE_SIZE    0x53
#define VC0706_COMMAND_READ_FBUF    0x32
#define FBUF_CURRENT_FRAME      0
#define FBUF_NEXT_FRAME       0
#define VC0706_COMMAND_FBUF_CTRL    0x36
#define VC0706_COMMAND_COMM_MOTION_CTRL   0x37
#define VC0706_COMMAND_COMM_MOTION_DETECTED 0x39
#define VC0706_COMMAND_POWER_SAVE_CTRL    0x3E
#define VC0706_COMMAND_COLOR_CTRL   0x3C
#define VC0706_COMMAND_MOTION_CTRL    0x42
#define VC0706_COMMAND_WRITE_DATA   0x31
#define VC0706_COMMAND_GET_FBUF_LEN   0x34
#define READ_DATA_BLOCK_NO      56
unsigned char   tx_counter;
unsigned char   tx_vcbuffer[20];
bool    tx_ready;
bool    rx_ready;
unsigned char   rx_counter;
unsigned char   VC0706_rx_buffer[80];
uint32_t  frame_length = 0;
uint32_t  vc_frame_address = 0;
uint32_t  last_data_length = 0;
// one Integer Variable to count for photo
// increase if you have difficulties conenctiong
// but it then will refresh less often
int waitForPhoto = 4;
int waitCount;
//////////////////////
void setup() {
  // reset w5100
  pinMode(10, OUTPUT);
  digitalWrite(10, HIGH);
  // open Serial2 connection to the camera
  Serial2.begin(115200);
  // set the jpeg compression of the camera
  // smaller number means smaller file, but less quality
  VC0706_compression_ratio(15);
  delay(100);
  pinMode(SDCARD_CS, OUTPUT);
  Sd2Card card;
  card.init(SPI_FULL_SPEED, SDCARD_CS);
  if (!SD.begin(SDCARD_CS)) {
    rsetFunc();
  }
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  // put your setup code here, to run once:
  TFT_BL_ON;
  Tft.TFTinit();
  setSyncProvider(RTC.get);
  page = 1;
  monthnow = month();
  yearnow = year();
  minutenow = minute();
  hournow = hour();
  npage = 1;
  humidmin = 50.00;
  dht.begin();
  sensor_hr1.begin();
  sensor_hr2.begin();
  TimeLord tardis;
  tardis.TimeZone(0);
  tardis.Position(LATITUDE, LONGITUDE);
  // pins
  pinMode(dnlamp, OUTPUT);
  pinMode(fogger, OUTPUT);
  pinMode(hlamp, OUTPUT);
  pinMode(hrock1, OUTPUT);
  pinMode(hrock2, OUTPUT);
  pinMode(fan, OUTPUT);
  pinMode(foggerwater, INPUT);
  myDoc = "daynow.txt";
  readsd();
  daynow = myData.toInt();
  myDoc = "hd.txt";
  readsd();
  humidday = myData.toInt();
  myDoc = "hs.txt";
  readsd();
  humidminset = myData.toFloat();
  myDoc = "atd.txt";
  readsd();
  ambitempday = myData.toInt();
  myDoc = "atdset.txt";
  readsd();
  hkdaytempdisp = myData.toFloat();
  myDoc = "atn.txt";
  readsd();
  ambitempnight = myData.toInt();
  myDoc = "atnset.txt";
  readsd();
  hknighttempdisp = myData.toFloat();
  myDoc = "ssetday.txt";
  readsd();
  ssday = myData.toInt();
  myDoc = "sriseday.txt";
  readsd();
  srday = myData.toInt();
  myDoc = "ssetmin.txt";
  readsd();
  ssminutesetdisp = myData.toInt();
  myDoc = "srisemin.txt";
  readsd();
  srminutesetdisp = myData.toInt();
  myDoc = "sriseh.txt";
  readsd();
  srhoursetdisp = myData.toInt();
  myDoc = "ssethour.txt";
  readsd();
  sshoursetdisp = myData.toInt();
}
//////////////////////
void loop() {
  // put your main code here, to run repeatedly:
  TimeLord tardis;
  tardis.DstRules(3, 2, 11, 1, 60);
  if (firsttimeon == 1) {
    tardis.TimeZone(-5 * 60);
    tardis.Position(LATITUDE, LONGITUDE);
    dlstime[5] = (year() - 2000);
    dlstime[4] = month();
    dlstime[3] = day();
    dlstime[2] = hour();
    dlstime[1] = minute();
    tardis.DST(dlstime);
    firsttimeon = 0;
  }
  // count down for photo time
  waitCount = waitCount - 1;
  if (waitCount < 2) {
    capture_photo("live.jpg");
    waitCount = waitForPhoto;
  }
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    int pos = 0;
    char clientReq[100];
    while (client.connected()) {
      if (client.available()) {
        // read what the client is requesting
        char c = client.read();
        if (c != '\n' && c != '\r') {
          clientReq[pos] = c;
          pos++;
          if (pos >= 100) pos = 99; // dont let the buffer overflow...
          continue;
        }
        // send a jpeg file or send html to display files
        // if there is a character after the 'GET /' request
        // send the jpeg file
        if ( clientReq[5] != ' ' ) {
          // ###### FIND OUT WHICH FILE THE CLIENT REQUEST HERE !!!
          File myFile = SD.open("live.jpg");
          // try to open file
          // if successfull, send header and jpeg data
          if (myFile) {
            client.println("HTTP/1.1 200 OK");
            client.println("Content-Type: image/jpg");
            client.println();
            byte clientBuf[64];
            int clientCount = 0;
            while (myFile.available())
            {
              clientBuf[clientCount] = myFile.read();
              clientCount++;
              if (clientCount > 63) {
                client.write(clientBuf, 64);
                clientCount = 0;
              }
            }
            if (clientCount > 0) {
              client.write(clientBuf, clientCount);
            }
            myFile.close();
          }
        } else {
          // there is no character after the 'GET /'
          // send HTML site
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");
          client.println("Refresh: 2");
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          client.print("Harold & Kumar's Enclosure");
          client.println("<br />");
          client.print(dayStr(weekday(now())));
          client.print(", ");
          client.print(monthStr(dlstime[4]));
          client.print(" ");
          client.print(dlstime[3]);
          client.print(", ");
          client.print(year());
          client.print(" at ");
          if (dlstime[2] < 10) {
            client.print("0");
          }
          client.print(dlstime[2]);
          client.print(":");
          if (minute() < 10) {
            client.print("0");
          }
          client.print(minute());
          client.print(":");
          if (second() < 10) {
            client.print("0");
          }
          client.print(second());
          client.println("<br />");
          client.println("<br />");
          client.print("Room Temperature = ");
          client.print(roomtemp);
          client.print(" ");
          client.print(char(176));
          client.print("F");
          client.println("<br />");
          client.println("<br />");
          client.print("Ambient Temperature = ");
          client.print(ambitempdisp);
          client.print(" ");
          client.print(char(176));
          client.print("F");
          client.println("<br />");
          client.print(" Range = ");
          if (night == 0) {
            client.print(hkdaytempdisp - .5);
          } else {
            client.print(hknighttempdisp - .5);
          }
          client.print(" ");
          client.print(char(176));
          client.print("F - ");
          if (night == 0) {
            client.print(hkdaytempdisp + .5);
          } else {
            client.print(hknighttempdisp + .5);
          }
          client.print(" ");
          client.print(char(176));
          client.print("F ");
          if (night == 0 && ambitempday > 0) {
            client.print("For ");
            client.print(ambitempday);
            client.print(" Day(s)");
          }
          if (night == 1 && ambitempnight > 0) {
            client.print(" For ");
            client.print(ambitempnight);
            client.print(" Day(s)");
          }
          client.println("<br />");
          client.println("<br />");
          client.print("Basking Temperature = ");
          client.print(hr1tempdisp);
          client.print(" ");
          client.print(char(176));
          client.print("F");
          client.println("<br />");
          client.print(" Range = ");
          client.print(88);
          client.print(" ");
          client.print(char(176));
          client.print("F - ");
          client.print(96);
          client.print(" ");
          client.print(char(176));
          client.print("F");
          client.println("<br />");
          client.println("<br />");
          client.print("Borrow Temperature = ");
          client.print(hr2tempdisp);
          client.print(" ");
          client.print(char(176));
          client.print("F");
          client.println("<br />");
          client.print(" Range = ");
          if (night == 0) {
            client.print(hkdaytempdisp - .5);
          } else {
            client.print(hknighttempdisp - .5);
          }
          client.print(" ");
          client.print(char(176));
          client.print("F - ");
          if (night == 0) {
            client.print(hkdaytempdisp + .5);
          } else {
            client.print(hknighttempdisp + .5);
          }
          client.print(" ");
          client.print(char(176));
          client.print("F");
          if (night == 0 && ambitempday > 0) {
            client.print(" For ");
            client.print(ambitempday);
            client.print(" Day(s)");
          }
          if (night == 1 && ambitempnight > 0) {
            client.print(" For ");
            client.print(ambitempnight);
            client.print(" Day(s)");
          }
          client.println("<br />");
          client.println("<br />");
          client.print("Humidity = ");
          client.print(humiddisp);
          client.print("%");
          client.println("<br />");
          client.print(" Range = ");
          client.print(humidminset);
          client.print("% - ");
          client.print(humidminset + 10);
          client.print("% ");
          if ( humidday > 0) {
            client.print("For ");
            client.print(humidday);
            client.print(" Day(s)");
          }
          client.println("<br />");
          client.println("<br />");
          client.print("Water Level = ");
          if (digitalRead(foggerwater) == HIGH) {
            client.print("Good");
          } else {
            client.print("Fill Now!");
          }
          client.println("<br />");
          client.print("Time = ");
          if (night == 0) {
            client.print("Day");
          } else {
            client.print("Night");
          }
          client.println("<br />");
          client.print("Sunrise Time = ");
          if (srhoursetdisp < 10) {
            client.print("0");
          }
          client.print(srhoursetdisp);
          client.print(":");
          if (srminutesetdisp < 10) {
            client.print("0");
          }
          client.print(srminutesetdisp);
          if (srday > 0) {
            client.print(" For ");
            client.print(srday);
            client.print(" Day(s)");
          }
          client.println("<br />");
          client.print("Sunset Time = ");
          if (sshoursetdisp < 10) {
            client.print("0");
          }
          client.print(sshoursetdisp);
          client.print(":");
          if (ssminutesetdisp < 10) {
            client.print("0");
          }
          client.print(ssminutesetdisp);
          if (ssday > 0) {
            client.print(" For ");
            client.print(ssday);
            client.print(" Day(s)");
          }
          client.println("<br />");
          client.println("<br />");
          client.print("Heat Lamp = ");
          if (hlpwr == 1) {
            client.print("ON");
          } else {
            client.print("OFF");
          }
          client.println("<br />");
          client.print("Fans = ");
          if (fanpwr == 1) {
            client.print("ON");
          } else {
            client.print("OFF");
          }
          client.println("<br />");
          client.print("Basking Rock = ");
          if (hr1pwr == 1) {
            client.print("ON");
          } else {
            client.print("OFF");
          }
          client.println("<br />");
          client.print("Borrow Rock = ");
          if (hr2pwr == 1) {
            client.print("ON");
          } else {
            client.print("OFF");
          }
          client.println("<br />");
          client.print("Fogger = ");
          if (foggerpwr == 1) {
            client.print("ON");
          } else {
            client.print("OFF");
          }
          client.println("<br />");
          client.println("<div align=center><img src='live.jpg' width='640' height='480'>");
          client.println("<p>");
          client.println("Live from Harold & Kumar</div>");
          client.println("</html>");
        }
        delay(1);
        //stopping client
        client.stop();
      }
    }
  }
  //new touch point
  Point p = ts.getPoint();
  p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240);
  p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320);
  if (p.z > __PRESURE) {
    // New Page
    if ((p.x < 120) && (p.y > 40) && (p.y < 70)) {
      if (page == 1) {
        page = 2;
        npage = 1;
      } else {
        page = 1;
        npage = 1;
      }
    }
    if ((p.x > 120) && (p.y > 40) && (p.y < 70)) {
      if (page > 2) {
        page = 2;
        npage = 1;
      } else {
        page = 3;
        npage = 1;
      }
    }
    if ((p.x < 120) && (p.y > 70) && (p.y < 100)) {
      if (page > 3) {
        page = 3;
        npage = 1;
      } else {
        page = 4;
        npage = 1;
      }
    }
    if ((p.x > 120) && (p.y > 70) && (p.y < 100)) {
      if (page == 5) {
        page = 4;
        npage = 1;
      } else {
        page = 5;
        npage = 1;
      }
    }
    if (page == 2) {
      if ((p.x > 140) && (p.x < 170) && (p.y > 220) && (p.y < 250)) { //+ set
        if (night == 1) {
          if (dnchan == 0) {
            hknighttempdisp = hknighttempdisp + .5;
            Tft.fillRectangle(48, 230, 72, 15, BLACK);
            Tft.drawFloat(hknighttempdisp, 48, 230, 2, CYAN);
            if (ambitempnight == 0 ) {
              ambitempnight = ambitempnight + 1;
              Tft.fillRectangle(84, 270, 36, 15, BLACK);
              Tft.drawNumber(ambitempnight, 84, 270, 2, CYAN);
            }
          } else {
            hkdaytempdisp = hkdaytempdisp + .5;
            Tft.fillRectangle(48, 230, 72, 15, BLACK);
            Tft.drawFloat(hkdaytempdisp, 48, 230, 2, CYAN);
            if (ambitempday == 0 ) {
              ambitempday = ambitempday + 1;
              Tft.fillRectangle(84, 270, 36, 15, BLACK);
              Tft.drawNumber(ambitempday, 84, 270, 2, CYAN);
            }
          }
        } else {
          if (dnchan == 0) {
            hkdaytempdisp = hkdaytempdisp + .5;
            Tft.fillRectangle(48, 230, 72, 15, BLACK);
            Tft.drawFloat(hkdaytempdisp, 48, 230, 2, CYAN);
            if (ambitempday == 0 ) {
              ambitempday = ambitempday + 1;
              Tft.fillRectangle(84, 270, 36, 15, BLACK);
              Tft.drawNumber(ambitempday, 84, 270, 2, CYAN);
            }
          } else {
            hknighttempdisp = hknighttempdisp + .5;
            Tft.fillRectangle(48, 230, 72, 15, BLACK);
            Tft.drawFloat(hknighttempdisp, 48, 230, 2, CYAN);
            if (ambitempnight == 0 ) {
              ambitempnight = ambitempnight + 1;
              Tft.fillRectangle(84, 270, 36, 15, BLACK);
              Tft.drawNumber(ambitempnight, 84, 270, 2, CYAN);
            }
          }
        }
      }
      if ((p.x > 200) && (p.x < 230) && (p.y > 220) && (p.y < 250)) { //- set
        if (night == 1) {
          if (dnchan == 0) {
            hknighttempdisp = hknighttempdisp - .5;
            Tft.fillRectangle(48, 230, 72, 15, BLACK);
            Tft.drawFloat(hknighttempdisp, 48, 230, 2, CYAN);
            if (ambitempnight == 0 ) {
              ambitempnight = ambitempnight + 1;
              Tft.fillRectangle(84, 270, 36, 15, BLACK);
              Tft.drawNumber(ambitempnight, 84, 270, 2, CYAN);
            }
          } else {
            hkdaytempdisp = hkdaytempdisp - .5;
            Tft.fillRectangle(48, 230, 72, 15, BLACK);
            Tft.drawFloat(hkdaytempdisp, 48, 230, 2, CYAN);
            if (ambitempday == 0 ) {
              ambitempday = ambitempday + 1;
              Tft.fillRectangle(84, 270, 36, 15, BLACK);
              Tft.drawNumber(ambitempday, 84, 270, 2, CYAN);
            }
          }
        } else {
          if (dnchan == 0) {
            hkdaytempdisp = hkdaytempdisp * .5;
            Tft.fillRectangle(48, 230, 72, 15, BLACK);
            Tft.drawFloat(hkdaytempdisp, 48, 230, 2, CYAN);
            if (ambitempday == 0 ) {
              ambitempday = ambitempday + 1;
              Tft.fillRectangle(84, 270, 36, 15, BLACK);
              Tft.drawNumber(ambitempday, 84, 270, 2, CYAN);
            }
          } else {
            hknighttempdisp = hknighttempdisp - .5;
            Tft.fillRectangle(48, 230, 72, 15, BLACK);
            Tft.drawFloat(hknighttempdisp, 48, 230, 2, CYAN);
            if (ambitempnight == 0 ) {
              ambitempnight = ambitempnight + 1;
              Tft.fillRectangle(84, 270, 36, 15, BLACK);
              Tft.drawNumber(ambitempnight, 84, 270, 2, CYAN);
            }
          }
        }
      }
      if ((p.x > 140) && (p.x < 170) && (p.y > 260) && (p.y < 290)) { //+ day
        if (night == 1) {
          if (dnchan == 0) {
            ambitempnight = ambitempnight + 1;
            Tft.fillRectangle(84, 270, 36, 15, BLACK);
            Tft.drawNumber(ambitempnight, 84, 270, 2, CYAN);
          } else {
            ambitempday = ambitempday + 1;
            Tft.fillRectangle(84, 270, 36, 15, BLACK);
            Tft.drawNumber(ambitempday, 84, 270, 2, CYAN);
          }
        } else {
          if (dnchan == 0) {
            ambitempday = ambitempday + 1;
            Tft.fillRectangle(84, 270, 36, 15, BLACK);
            Tft.drawNumber(ambitempday, 84, 270, 2, CYAN);
          } else {
            ambitempnight = ambitempnight + 1;
            Tft.fillRectangle(84, 270, 36, 15, BLACK);
            Tft.drawNumber(ambitempnight, 84, 270, 2, CYAN);
          }
        }
      }
      if ((p.x > 200) && (p.x < 230) && (p.y > 260) && (p.y < 290)) { //- day
        if (night == 1) {
          if (dnchan == 0) {
            ambitempnight = ambitempnight - 1;
            Tft.fillRectangle(84, 270, 36, 15, BLACK);
            Tft.drawNumber(ambitempnight, 84, 270, 2, CYAN);
          } else {
            ambitempday = ambitempday - 1;
            Tft.fillRectangle(84, 270, 36, 15, BLACK);
            Tft.drawNumber(ambitempday, 84, 270, 2, CYAN);
          }
        } else {
          if (dnchan == 0) {
            ambitempday = ambitempday - 1;
            Tft.fillRectangle(84, 270, 36, 15, BLACK);
            Tft.drawNumber(ambitempday, 84, 270, 2, CYAN);
          } else {
            ambitempnight = ambitempnight - 1;
            Tft.fillRectangle(84, 270, 36, 15, BLACK);
            Tft.drawNumber(ambitempnight, 84, 270, 2, CYAN);
          }
        }
      }
      if ((p.x > 60) && (p.x < 180) && (p.y > 300) && (p.y < 330)) {
        if (dnchan == 0) {
          dnchan = 1;
        } else {
          dnchan = 0;
        }
        npage = 1;
      }
    }
    if (page == 3) {
      if ((p.x > 60) && (p.x < 90) && (p.y > 170) && (p.y < 200)) { //+ humidity
        humidminset = humidminset + 1;
        if (humidday == 0) {
          humidday = 1;
          Tft.fillRectangle(60, 210, 36, 15, BLACK);
          Tft.drawNumber(humidday, 60, 210, 2, CYAN);
        }
        Tft.fillRectangle(72, 150, 60, 15, BLACK);
        Tft.drawFloat(humidminset, 72, 150, 2, CYAN);
        Tft.fillRectangle(146, 150, 60, 15, BLACK);
        Tft.drawFloat(humidminset + 10, 146, 150, 2, CYAN);
      }
      if ((p.x > 120) && (p.x < 150) && (p.y > 170) && (p.y < 200)) { // - Humidity
        humidminset = humidminset - 1;
        if (humidday == 0) {
          humidday = 1;
          Tft.fillRectangle(60, 210, 36, 15, BLACK);
          Tft.drawNumber(humidday, 60, 210, 2, CYAN);
        }
        Tft.fillRectangle(72, 150, 60, 15, BLACK);
        Tft.drawFloat(humidminset, 72, 150, 2, CYAN);
        Tft.fillRectangle(146, 150, 60, 15, BLACK);
        Tft.drawFloat(humidminset + 10, 146, 150, 2, CYAN);
      }
      if ((p.x > 60) && (p.x < 90) && (p.y > 230) && (p.y < 260)) { // + humid day
        humidday = humidday + 1;
        Tft.fillRectangle(60, 210, 36, 15, BLACK);
        Tft.drawNumber(humidday, 60, 210, 2, CYAN);
      }
      if ((p.x > 120) && (p.x < 150) && (p.y > 230) && (p.y < 260)) { // - humid day
        humidday = humidday - 1;
        if (humidday < 0) {
          humidday = 0;
        }
        Tft.fillRectangle(60, 210, 36, 15, BLACK);
        Tft.drawNumber(humidday, 60, 210, 2, CYAN);
      }
    }
    if (page == 4) {
      if ((p.x > 60) && (p.x < 90) && (p.y > 130) && (p.y < 160)) { // + min on sunrise
        srminutesetdisp = srminutesetdisp + 1;
        if (srminutesetdisp > 59) {
          srminutesetdisp = 0;
          srhoursetdisp = srhoursetdisp + 1;
          if (srhoursetdisp > 24) {
            srhoursetdisp = 0;
          }
        }
        if (srday == 0) {
          srday = 1;
          Tft.fillRectangle(60, 170, 36, 15, BLACK);
          Tft.drawNumber(srday, 60, 170, 2, CYAN);
        }
        Tft.fillRectangle(110, 110, 24, 15, BLACK);
        if (srhoursetdisp > 9) {
          Tft.drawNumber(srhoursetdisp, 110, 110, 2, CYAN);
        } else {
          Tft.drawNumber(0, 110, 110, 2, CYAN);
          Tft.drawNumber(srhoursetdisp, 122, 110, 2, CYAN);
        }
        Tft.fillRectangle(146, 110, 24, 15, BLACK);
        if (srminutesetdisp > 9) {
          Tft.drawNumber(srminutesetdisp, 146, 110, 2, CYAN);
        } else {
          Tft.drawNumber(0, 146, 110, 2, CYAN);
          Tft.drawNumber(srminutesetdisp, 158, 110, 2, CYAN);
        }
      }
      if ((p.x > 120) && (p.x < 150) && (p.y > 130) && (p.y < 160)) { // - min on sunrise
        srminutesetdisp = srminutesetdisp - 1;
        if (srminutesetdisp < 0) {
          srminutesetdisp = 59;
          srhoursetdisp = srhoursetdisp - 1;
          if (srhoursetdisp < 0) {
            srhoursetdisp = 24;
          }
        }
        if (srday == 0) {
          srday = 1;
          Tft.fillRectangle(60, 170, 36, 15, BLACK);
          Tft.drawNumber(srday, 60, 170, 2, CYAN);
        }
        Tft.fillRectangle(110, 110, 24, 15, BLACK);
        if (srhoursetdisp > 9) {
          Tft.drawNumber(srhoursetdisp, 110, 110, 2, CYAN);
        } else {
          Tft.drawNumber(0, 110, 110, 2, CYAN);
          Tft.drawNumber(srhoursetdisp, 122, 110, 2, CYAN);
        }
        Tft.fillRectangle(146, 110, 24, 15, BLACK);
        if (srminutesetdisp > 9) {
          Tft.drawNumber(srminutesetdisp, 146, 110, 2, CYAN);
        } else {
          Tft.drawNumber(0, 146, 110, 2, CYAN);
          Tft.drawNumber(srminutesetdisp, 158, 110, 2, CYAN);
        }
      }
      if ((p.x > 110) && (p.x < 140) && (p.y > 170) && (p.y < 200)) { // +day set for sunrise
        srday = srday + 1;
        Tft.fillRectangle(60, 170, 36, 15, BLACK);
        Tft.drawNumber(srday, 60, 170, 2, CYAN);
      }
      if ((p.x > 170) && (p.x < 200) && (p.y > 170) && (p.y < 200)) { // - day set for sunrise
        srday = srday - 1;
        if (srday < 0) {
          srday = 0;
        }
        Tft.fillRectangle(60, 170, 36, 15, BLACK);
        Tft.drawNumber(srday, 60, 170, 2, CYAN);
      }
      if ((p.x > 60) && (p.x < 90) && (p.y > 230) && (p.y < 260)) { // + min sunset
        ssminutesetdisp = ssminutesetdisp + 1;
        if (ssminutesetdisp > 59) {
          ssminutesetdisp = 0;
          sshoursetdisp = sshoursetdisp + 1;
          if (sshoursetdisp > 24) {
            sshoursetdisp = 0;
          }
        }
        if (ssday == 0) {
          ssday = 1;
          Tft.fillRectangle(60, 270, 36, 15, BLACK);
          Tft.drawNumber(ssday, 60, 270, 2, CYAN);
        }
        Tft.fillRectangle(110, 210, 24, 15, BLACK);
        if (sshoursetdisp > 9) {
          Tft.drawNumber(sshoursetdisp, 110, 210, 2, CYAN);
        } else {
          Tft.drawNumber(0, 110, 210, 2, CYAN);
          Tft.drawNumber(sshoursetdisp, 122, 210, 2, CYAN);
        }
        Tft.fillRectangle(146, 210, 24, 15, BLACK);
        if (ssminutesetdisp > 9) {
          Tft.drawNumber(ssminutesetdisp, 146, 210, 2, CYAN);
        } else {
          Tft.drawNumber(0, 146, 210, 2, CYAN);
          Tft.drawNumber(ssminutesetdisp, 158, 210, 2, CYAN);
        }
      }
      if ((p.x > 120) && (p.x < 150) && (p.y > 230) && (p.y < 260)) { //- min for sunset
        ssminutesetdisp = ssminutesetdisp - 1;
        if (ssminutesetdisp < 0) {
          ssminutesetdisp = 59;
          sshoursetdisp = sshoursetdisp - 1;
          if (sshoursetdisp < 0) {
            sshoursetdisp = 24;
          }
        }
        if (ssday == 0) {
          ssday = 1;
          Tft.fillRectangle(60, 270, 36, 15, BLACK);
          Tft.drawNumber(ssday, 60, 270, 2, CYAN);
        }
        Tft.fillRectangle(110, 210, 24, 15, BLACK);
        if (sshoursetdisp > 9) {
          Tft.drawNumber(sshoursetdisp, 110, 210, 2, CYAN);
        } else {
          Tft.drawNumber(0, 110, 210, 2, CYAN);
          Tft.drawNumber(sshoursetdisp, 122, 210, 2, CYAN);
        }
        Tft.fillRectangle(146, 210, 24, 15, BLACK);
        if (ssminutesetdisp > 9) {
          Tft.drawNumber(ssminutesetdisp, 146, 210, 2, CYAN);
        } else {
          Tft.drawNumber(0, 146, 210, 2, CYAN);
          Tft.drawNumber(ssminutesetdisp, 158, 210, 2, CYAN);
        }
      }
      if ((p.x > 110) && (p.x < 140) && (p.y > 270) && (p.y < 300)) { //+ day for sunset
        ssday = ssday + 1;
        Tft.fillRectangle(60, 270, 36, 15, BLACK);
        Tft.drawNumber(ssday, 60, 270, 2, CYAN);
      }
      if ((p.x > 170) && (p.x < 200) && (p.y > 270) && (p.y < 300)) { //- day set for sunset
        ssday = ssday - 1;
        if (ssday < 0) {
          ssday = 0;
        }
        Tft.fillRectangle(60, 270, 36, 15, BLACK);
        Tft.drawNumber(ssday, 60, 270, 2, CYAN);
      }
    }
    tpage = minute() + 5;
    if (tpage > 59) {
      tpage = tpage - 60;
    }
  }
  //page change
  if (npage == 1) {
    if (page == 1) {
      allpage();
      pageone();
    }
    if (page == 2) {
      allpage();
      pagetwo();
    }
    if (page == 3) {
      allpage();
      pagethree();
    }
    if (page == 4) {
      allpage();
      pagefour();
    }
    if (page == 5) {
      allpage();
      pagefive();
    }
...

This file has been truncated, please download it to see its full contents.

Credits

hagakure

hagakure

1 project • 7 followers

Comments