Hello dear,
Ive done a little progress with your help. ![]()
At the moment, the matching value of 5000 is passed to the function matching(), if button 1 is clicked. When we press button 2, the value of 2000 should be passed to the function matching.
The fault at this point is, that in case button 2 is clicked, the serial monitor still displays 5000.
So still pass the wrong variables with my code. ![]()
For reference the current code, without mangling (:D):
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "URTouch.h"
#define TFT_DC 2
#define TFT_CS 10
#define TFT_RST 8
#define TFT_MISO 12
#define TFT_MOSI 11
#define TFT_CLK 13
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
#define t_SCK 3
#define t_CS 4
#define t_MOSI 5
#define t_MISO 6
#define t_IRQ 7
#define BLUE 0x001F
#define GREEN 0x07E0
#define WHITE 0xFFFF
#define BLACK 0x0000
#define YELLOW 0xFFF0
#define RED 0xF800
char currentpage;
URTouch ts(t_SCK, t_CS, t_MOSI, t_MISO, t_IRQ);
int x, y;
int vmax;
int vmin;
int matchtime;
unsigned long previousMillis;
const uint8_t ledPins[4] = { A1, A2, A3, A4 };
const uint8_t lastIndex = sizeof(ledPins) - 1;
const uint16_t blinkDuration = 200; //time period for void ventilation
uint32_t lastBlink;
uint8_t currLed = lastIndex;
//////////////////////////////
void setup() {
pinMode(A1, OUTPUT);
pinMode(A2, OUTPUT);
pinMode(A3, OUTPUT);
pinMode(A4, OUTPUT);
Serial.begin(9600);
tft.begin();
tft.setRotation(3);
tft.fillScreen(ILI9341_WHITE);
ts.InitTouch();
ts.setPrecision(PREC_EXTREME);
currentpage = '0'; // standard starting page after booting is home screen
drawhomescreen();
for (auto pin : ledPins) {
pinMode(pin, OUTPUT);
}
}
void loop() {
// home screen setup
if (currentpage == '0') {
// add function: set test variables to 0
if (ts.dataAvailable()) {
ts.read();
x = ts.getX();
y = ts.getY();
if ((x >= 50) && (x <= 125) && (y >= 20) && (y <= 60)) { // button 1 clicked
// set the type specific parameters, which are used in void matching e.d.
int matchtime = 5000; // 5s testing time for this type
vmin = 20; // minvolume for this type
vmax = 23; // max volumen for this type
currentpage = '1';
drawventilate(); // display next page
}
if((x>=200) && (x<=275) && (y>=20) && (y<=60)){ // button 2 clicked
// set the type specific parameters, which are used in void matching e.d.
int matchtime = 2000; // 5s testing time for this type
vmin = 20; // minvolume for this type
vmax = 23; // max volumen for this type
currentpage = '1';
drawventilate(); // display next page
}
//if((x>=50) && (x<=125) && (y>=90) && (y<=130)){ } add PARAMETER for 600
//if((x>=50) && (x<=125) && (y>=160) && (y<=200)){ } add PARAMETER for 900
}
}
if (currentpage == '1') {
startventilate(); // making rail air-free and adjusting pressure
if (ts.dataAvailable()) {
ts.read();
x = ts.getX();
y = ts.getY();
if ((x >= 0) && (x <= 320) && (y >= 0) && (y <= 240)) {
digitalWrite(A1, LOW);
digitalWrite(A2, LOW);
digitalWrite(A3, LOW);
digitalWrite(A4, LOW);
currentpage = '2';
leakcheck(); // display screen "start leak check"
}
}
}
if (currentpage == '2') { // leak check
if (ts.dataAvailable()) {
ts.read();
x = ts.getX();
y = ts.getY();
if ( (x >= 0) && (x <= 320) && (y >= 0) && (y <= 240) ) {
currentpage = '3';
drawmatching(); //display screen "start matching"
}
}
}
if (currentpage == '3') {
matching(5000);
if (ts.dataAvailable()) {
ts.read();
x = ts.getX();
y = ts.getY();
if ( (x >= 0) && (x <= 320) && (y >= 0) && (y <= 240) ) {
currentpage = '4';
}
}
}
if (currentpage == '4') {
if (ts.dataAvailable()) {
ts.read();
x = ts.getX();
y = ts.getY();
drawresults();
if ( (x >= 0) && (x <= 320) && (y >= 0) && (y <= 240) ) {
currentpage == '0';
}
}
}
}
// (ADD PROGRAM FOR PROOF IDLE MATCH / IDLE OPENING TIME)
void drawventilate() {
tft.fillScreen(ILI9341_WHITE);
tft.setTextColor(BLACK);
tft.setCursor(05, 20);
tft.setTextSize(2);
tft.print("STARTE PUMPE & EINSTELLEN:");
tft.setCursor(05, 70);
tft.setTextSize(2);
tft.print("3,0 Bar Druck ");
//fertig button
tft.fillRect (90, 160, 140, 40, BLUE);
tft.drawRect (90, 160, 140, 40, WHITE);
tft.setCursor(100, 170);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.print("FERTIG");
}
void drawhomescreen() {
// creating home screen
tft.fillScreen(ILI9341_WHITE);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(1);
tft.setCursor(80, 5);
tft.print("Duesengroesse waehlen");
tft.fillRect (50, 20, 75, 40, BLUE);
tft.drawRect (50, 20, 75, 40, BLACK);
tft.setCursor(65, 30);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.print("400");
tft.fillRect (200, 20, 75, 40, BLUE);
tft.drawRect (200, 20, 75, 40, BLACK);
tft.setCursor(215, 30);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.print("470");
tft.fillRect (50, 90, 75, 40, BLUE);
tft.drawRect (50, 90, 75, 40, BLACK);
tft.setCursor(65, 100);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.print("600");
tft.fillRect (50, 160, 75, 40, BLUE);
tft.drawRect (50, 160, 75, 40, BLACK);
tft.setCursor(65, 170);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.print("900");
}
void startventilate() {
uint32_t topLoop = millis();
if (topLoop - lastBlink >= blinkDuration) {
lastBlink = topLoop;
digitalWrite(ledPins[currLed], LOW); // switch off last injector
if (++currLed > lastIndex) {
currLed = 0;
}
digitalWrite(ledPins[currLed], HIGH); // turn next injector on
}
}
void leakcheck() {
tft.fillScreen(ILI9341_WHITE);
tft.setTextColor(BLACK);
tft.setCursor(50, 20);
tft.setTextSize(3);
tft.print("LEAK CHECK!");
tft.setCursor(50, 50);
tft.setTextColor(RED);
tft.setTextSize(2);
tft.print("ALLE DUESEN DICHT?");
tft.setCursor(50, 80);
tft.setTextSize(2);
tft.print("VENTIL SCHLIESSEN!");
//fertig button
tft.fillRect (30, 160, 250, 40, BLUE);
tft.drawRect (30, 160, 250, 40, WHITE);
tft.setCursor(35, 170);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("DUESEN DICHT");
}
void drawmatching() {
tft.fillScreen(ILI9341_WHITE);
tft.setTextColor(BLACK);
tft.setCursor(50, 20);
tft.setTextSize(3);
tft.print("Einstellen");
tft.setCursor(50, 50);
tft.setTextSize(2);
tft.print("3,0 Bar Druck ");
//fertig button einblenden
tft.fillRect (90, 160, 140, 40, BLUE);
tft.drawRect (90, 160, 140, 40, WHITE);
tft.setCursor(100, 170);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.print("FERTIG");
}
// CODE FOR MATCHING
void matching(int matchtime) {
Serial.print("zeit=");
Serial.print(matchtime);
}
void drawresults() {
tft.fillScreen(ILI9341_WHITE);
tft.setTextColor(RED);
tft.setCursor(10, 30);
tft.setTextSize(2);
tft.print("Werte pruefen!");
tft.fillScreen(ILI9341_WHITE);
tft.setTextColor(BLACK);
tft.setCursor(10, 90);
tft.setTextSize(3);
tft.print("MINIMUM");
tft.setCursor(10, 1300);
tft.setTextSize(3);
tft.print("MAXIMUM");
tft.setCursor(150, 90);
tft.setTextSize(3);
tft.print('vmin');
tft.setCursor(150, 130);
tft.setTextSize(3);
tft.print('vmax');
//fertig button
tft.fillRect (90, 160, 140, 40, BLUE);
tft.drawRect (90, 160, 140, 40, WHITE);
tft.setCursor(100, 170);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.print("FERTIG");
}