Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <SdFat.h>
- #include <SPIflash.h>
- #include <UTFT.h>
- #include <UTFT_SPIflash.h>
- #include <CapacitiveSensor.h>
- #include <DCF77.h>
- #include <Time.h>
- #include <UTFT_SdRaw.h>
- #include <UTouch.h>
- #ifndef __time_t_defined
- typedef unsigned long time_t;
- #endif
- #define DCF_PIN 23
- #define DCF_INTERRUPT 23
- #define SD_CHIP_SELECT 53
- SdFat sd;
- time_t prevDisplay = 0;
- time_t time;
- extern uint8_t SmallFont[];
- int count = 0 ;
- const int maxpin = 8;
- const int minpin = 9;
- int maxpinstate = 0;
- int minpinstate = 0;
- long minlvl = 0;
- long maxlvl = 0;
- long offset = 0;
- long prozent1 = 0;
- long prozent2 = 0;
- int firststart = 1;
- byte dispScreen = 1;
- byte mistScreen = 1;
- byte fanScreen = 1;
- byte fogScreen = 1;
- uint8_t fileid;
- uint16_t filetype;
- byte zz = 0;
- DCF77 DCF = DCF77(DCF_PIN, DCF_INTERRUPT);
- CapacitiveSensor liquidLevel = CapacitiveSensor(12, 13);
- UTFT myGLCD(CTE50, 25, 26, 27, 28);
- UTouch myTouch( 6, 5, 4, 3, 2);
- SPIflash myFlash(52);
- UTFT_SPIflash myFlashFiles(&myGLCD, &myFlash);
- UTFT_SdRaw myFiles(&myGLCD);
- void setup()
- {
- Serial.begin(9600);
- DCF.Start();
- setSyncInterval(30);
- setSyncProvider(DCF.getTime);
- Serial.println("Start!");
- pinMode(maxpin, INPUT);
- pinMode(minpin, INPUT);
- myGLCD.InitLCD();
- myGLCD.setFont(SmallFont);
- myGLCD.clrScr();
- myGLCD.setDisplayPage(1);
- myFlash.begin();
- myTouch.InitTouch();
- myTouch.setPrecision(PREC_MEDIUM);
- bool mysd = 0;
- // see if the card is present and can be initialized:
- while (!mysd)
- {
- if (!sd.begin(SD_CHIP_SELECT, SPI_FULL_SPEED)) {
- Serial.println(F("Card failed, or not present"));
- Serial.println(F("Retrying...."));
- }
- else
- {
- mysd = 1;
- Serial.println(F("Card initialised."));
- }
- }
- Serial.println(F("Initialising LCD."));
- if (myFlash.ID_device == 0)
- {
- myGLCD.print("Unknown flash device!", 0, 0);
- Serial.println("Unknown flash device!");
- while (true) {};
- }
- Serial.println("Waiting for DCF77 time ... ");
- Serial.println("It will take at least 2 minutes until a first update can be processed.");
- myGLCD.setWritePage(0);
- myGLCD.clrScr();
- myFiles.loadcpld(230, 40, 378, 268, "Logo.raw", 0, 4);
- myFiles.loadcpld(340, 360, 149, 47, "Copy.raw", 0, 4);
- myGLCD.setDisplayPage(0);
- myFiles.loadcpld(0, 0, 800, 480, "1Home.raw", 1, 2);
- myFiles.loadcpld(0, 0, 800, 480, "2Lights.raw", 2, 2);
- myFiles.loadcpld(0, 0, 800, 480, "3TempGHL.raw", 3, 2);
- myFiles.loadcpld(124, 365, 73, 75, "DegC.raw", 3, 6);
- myFiles.loadcpld(0, 0, 800, 480, "46SchedG.raw", 4, 2);
- myFiles.loadcpld(0, 0, 800, 480, "5MistG.raw", 7, 2);
- myFiles.loadcpld(0, 0, 800, 480, "7Clock.raw", 5, 2);
- myFiles.loadcpld(0, 0, 800, 480, "8Screen.raw", 6, 2);
- screenHome();
- }
- void loop()
- {
- time_t DCFtime = DCF.getTime(); // Check if new DCF77 time is available
- fileid = 0;
- filetype = 0;
- count++ ;
- maxpinstate = digitalRead(maxpin);
- minpinstate = digitalRead(minpin);
- long total = liquidLevel.capacitiveSensor(50);
- myGLCD.print(" ", 280 , 10);
- myGLCD.printNumI(total, 280 , 10);
- if (firststart == 1) {
- Serial.println("Warte auf MIN Wert...");
- myGLCD.print("Warte auf MIN Wert...", 30, 20);
- Serial.println("Warte auf MAX Wert...");
- myGLCD.print("Warte auf MAX Wert...", 30, 50);
- // if (minpinstate == HIGH) {
- if (count == 3) {
- Serial.println("MIN WERT GESETZT auf:");
- myGLCD.print("MIN WERT GESETZT auf:", 30, 35);
- minlvl = total;
- Serial.print(minlvl);
- myGLCD.printNumI(minlvl, 200, 35);
- delay(500);
- }
- // if (maxpinstate == HIGH) {
- if (count == 5) {
- Serial.println("MAX WERT GESETZT auf:");
- myGLCD.print("MAX WERT GESETZT auf:", 30, 65);
- maxlvl = total;
- Serial.print(maxlvl);
- myGLCD.printNumI(maxlvl, 200, 65);
- delay(500);
- firststart = 0;
- myGLCD.clrScr();
- }
- }
- if (firststart == 0) {
- myGLCD.setDisplayPage(1);
- screenHome();
- processMyTouch();
- prozent1 = maxlvl / 100;
- prozent2 = total / prozent1;
- myGLCD.print(" ", 40, 10);
- myGLCD.print(" ", 40, 30);
- myGLCD.print(" ", 40, 50);
- myGLCD.print(" ", 40, 70);
- myGLCD.print(" ", 40, 90);
- myGLCD.print(" ", 40, 110);
- myGLCD.print("Max:", 10, 10);
- myGLCD.print("Min:", 10, 30);
- myGLCD.print("LVL:", 10, 50);
- myGLCD.print("Hour:", 10, 70);
- myGLCD.print("Min:", 10, 90);
- myGLCD.print("Sek:", 10, 110);
- myGLCD.printNumI(maxlvl, 40, 10);
- myGLCD.printNumI(minlvl, 40, 30);
- myGLCD.printNumI(prozent2, 40, 50);
- myGLCD.printNumI(hour(), 45, 70);
- myGLCD.printNumI(minute(), 45, 90);
- myGLCD.printNumI(second(), 45, 110);
- /*
- Serial.println("max:");
- Serial.println(maxlvl);
- Serial.println("min:");
- Serial.println(minlvl);
- Serial.println("prozent1:");
- Serial.println(prozent1);
- Serial.println("prozent2:");
- Serial.println(prozent2);
- */
- }
- // delay (400);
- }
- void DoScreen(byte page, byte screen) {
- myGLCD.setDisplayPage(page);
- myGLCD.setWritePage(page);
- dispScreen = screen;
- }
- void screenHome()
- {
- DoScreen(1, 1);
- Serial.println(F("Home Screen"));
- }
- void screenLights()
- {
- DoScreen(2, 2);
- Serial.println(F("Lights Screen"));
- }
- void screenTemp() {
- DoScreen(3, 3);
- Serial.println(F("Temp Screen"));
- }
- void screenFogger()
- {
- myFiles.loadcpld(21, 6, 336, 74, "FogTitle.raw", 4, 6);
- DoScreen(4, 4);
- Serial.println(F("Fogger Screen"));
- //
- }
- void screenMist()
- {
- DoScreen(7, 5);
- Serial.println(F("Misting Screen"));
- }
- void screenFan()
- {
- myFiles.loadcpld(21, 6, 336, 74, "FanTitle.raw", 4, 6);
- DoScreen(4, 6);
- Serial.println(F("Fan Screen"));
- }
- void screenClock()
- {
- DoScreen(5, 7);
- Serial.println(F("Clock Screen"));
- }
- void screenScreen()
- {
- DoScreen(6, 8);
- Serial.println(F("Screen Screen"));
- }
- void processMyTouch()
- {
- myTouch.read();
- word x = myTouch.getX();
- word y = myTouch.getY();
- switch (dispScreen)
- {
- case 1:
- if ((y >= 64) && (y < 114))
- {
- if ((x >= 371) && ( x < 421)) // 'Secret button'
- {
- Serial.println(F("SECRET MENU"));
- }
- }
- if ((y >= 117) && (y < 235))
- {
- if ((x >= 59) && (x <= 134)) // Light Settings Page
- {
- screenLights();
- }
- if ((x >= 175) && (x <= 240)) // Temp Settings Page
- {
- screenTemp();
- }
- if ((x >= 270) && (x <= 362)) // Fogger Settings Page
- {
- screenFogger();
- }
- }
- if (( y >= 285) && (y < 411)) {
- if ((x >= 46) && (x <= 141))
- {
- screenMist();
- }
- if ((x >= 171) && (x <= 237))
- {
- screenFan();
- }
- if ((x >= 270) && (x <= 370))
- {
- screenClock();
- }
- }
- if ((x >= 712) && (x <= 779) && (y >= 13) && (y <= 77))
- {
- screenScreen();
- }
- break;
- case 2:
- if ((x >= 363) && (x <= 444) && (y >= 422) && (y <= 479))
- {
- //screenHome();
- }
- break;
- case 3:
- if ((x >= 363) && (x <= 444) && (y >= 422) && (y <= 479) || zz >= 20)
- {
- screenHome();
- }
- break;
- case 4:
- if ((x >= 363) && (x < 445) && (y >= 422) && (y < 480))
- {
- screenHome();
- }
- break;
- case 5:
- if ((x >= 363) && (x < 445) && (y >= 422) && (y < 480))
- {
- screenHome();
- }
- break;
- case 6:
- if ((x >= 363) && (x < 445) && (y >= 422) && (y < 480))
- {
- screenHome();
- }
- break;
- case 7:
- if ((x >= 363) && (x <= 444) && (y >= 422) && (y < 480))
- {
- screenHome();
- }
- break;
- case 8:
- if ((x >= 363) && (x <= 444) && (y >= 422) && (y < 480))
- {
- screenHome();
- }
- break;
- case 9:
- if (((x >= 365) && (x <= 440)) && ((y >= 420) && (y < 480)))
- {
- screenHome();
- }
- break;
- }
- }
- void printDigits(int digits) {
- // utility function for digital clock display: prints preceding colon and leading 0
- Serial.print(":");
- if (digits < 10)
- Serial.print('0');
- Serial.print(digits);
- }
- unsigned long getDCFTime()
- {
- time_t DCFtime = DCF.getTime();
- // Indicator that a time check is done
- if (DCFtime != 0) {
- Serial.print("X");
- }
- return DCFtime;
- }
Advertisement
Add Comment
Please, Sign In to add comment