Empfänger:
#include <UTFT.h> //16bit TFT screen library
#include <ITDB02_Touch.h> //Touchscreen library
#include <Wire.h> //One Wire library
#include <DS1307new.h> //RTC library
#include <SPI.h> //Adafruit SD Card library mit SPI
#include <SD.h> //Adafruit SD Card library mit SPI
UTFT myGLCD(ITDB32WC,38,39,40,41); //Pins für TFT
ITDB02_Touch myTouch(6,5,4,3,2); //Pins für Touch
extern uint8_t BigFont[]; //Schriftarten
extern uint8_t SmallFont[];
extern uint8_t SevenSegNumFont[];
extern uint8_t SevenSegmentFull[];
extern uint8_t various_symbols[];
char ph_1;
long sd_previousMillis = 0; //Variablen für SD Card
int sd_state = LOW;
//****Werte die angepasst werden können****//
long sd_time = 10; //Logging Interval auf SD Card (In Minuten)
float ph_setpoint_min = 5.7; //Bereich für PH Anzeige Farbe
float ph_setpoint_max = 6.1;
//*****************************************//
void setup()
{
graphSetup(); //Initialsiert TFT
sdSetup(); //Initialisiert SD Card
Serial1.begin(9600); //Serielle Ausgabe ph_1
}
void loop()
{
graphLoop(); //Loop für TFT
receiveLoop(); //Loop Incoming Data
sdLoop(); //Loop SD Card
}
void graphSetup() //Initialisiert TFT
{
myGLCD.InitLCD(LANDSCAPE); //LANDSCAPE oder PORTRAIT
myGLCD.clrScr();
myTouch.InitTouch(LANDSCAPE); //LANDSCAPE oder PORTRAIT
myTouch.setPrecision(PREC_HI); //Touch Präzision
mainscr(); //Default screen ist mainscr
}
void sdSetup()
{
pinMode(SS, OUTPUT);
if (!SD.begin(10, 11, 12, 13))
{
return;
}
}
void receiveLoop()
{
if (Serial1.available()) {
ph_1 = Serial1.read();
}
}
void sdLoop()
{
unsigned long sd_currentMillis = millis();
if (sd_currentMillis - sd_previousMillis > ((sd_time*1000)*60))
{
sd_previousMillis = sd_currentMillis;
if (sd_state == LOW)
{
sd_state = HIGH;
File data1 = SD.open("becken1.csv", FILE_WRITE);
if (data1)
{
RTC.getTime();
data1.print(RTC.day, DEC);
data1.print('.');
data1.print(RTC.month, DEC);
data1.print('.');
data1.print(RTC.year, DEC);
data1.print(';');
data1.print(RTC.hour, DEC);
data1.print(':');
data1.print(RTC.minute, DEC);
data1.print(':');
data1.print(RTC.second, DEC);
data1.print(';');
data1.print(ph_1, 2);
data1.println();
data1.close();
}
}
else
{
sd_state = LOW;
}
}
}
void graphLoop()
{
delay(500); //Dient als Refresh Time
//Datum anzeigen
RTC.getTime();
myGLCD.setBackColor(VGA_BLACK);
myGLCD.setFont(BigFont);
myGLCD.setColor(VGA_WHITE);
myGLCD.printNumI(RTC.day, 132, 220);
myGLCD.print(".", 162, 220);
myGLCD.printNumI(RTC.month, 175, 220);
myGLCD.printNumI(RTC.year, 240, 220);
//Zeit anzeigen
myGLCD.printNumI(RTC.hour, 15, 220);
myGLCD.print(":", 50, 220);
myGLCD.printNumI(RTC.minute, 65, 220);
//PH anzeigen
myGLCD.setBackColor(VGA_BLACK);
myGLCD.setFont(BigFont);
if (ph_1 > ph_setpoint_max)
myGLCD.setColor(VGA_BLUE);
else if (ph_1 < ph_setpoint_min)
myGLCD.setColor(VGA_RED);
else
myGLCD.setColor(VGA_GREEN);
myGLCD.printNumF(ph_1, 0, 52, 38);
}
void mainscr()
{
myGLCD.fillScr(VGA_GREEN);
//Rahmen Oben
myGLCD.setColor(VGA_WHITE);
myGLCD.fillRoundRect (2, 2, 317, 214);
myGLCD.setColor(VGA_BLACK);
myGLCD.fillRoundRect (3, 3, 316, 213);
myGLCD.setColor(VGA_WHITE);
//Rahmen Linien
myGLCD.drawLine(2, 25, 317, 25);
myGLCD.drawLine(30, 3, 30, 214);
myGLCD.drawLine(122, 3, 122, 214);
myGLCD.drawLine(222, 3, 222, 214);
//Rahmen Unten
myGLCD.setColor(VGA_WHITE);
myGLCD.fillRoundRect (2, 238, 317, 217);
myGLCD.setColor(VGA_BLACK);
myGLCD.fillRoundRect (3, 237, 316, 218);
//Viereck oben links
myGLCD.setColor(VGA_WHITE);
myGLCD.fillRoundRect (5, 5, 27, 22);
myGLCD.setColor(VGA_GREEN);
myGLCD.fillRoundRect (6, 6, 26, 21);
//Titel Text
myGLCD.setBackColor(VGA_BLACK);
myGLCD.setFont(SmallFont);
myGLCD.setColor(VGA_WHITE);
myGLCD.print("Becken 1", 45, 8);
myGLCD.print("pH", 9, 40);
}