#include <Wire.h>
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#define TFT_DC 0
#define TFT_CS 15
#define TFT_SDA 13
#define TFT_SCK 14
#define TFT_RST 2
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_SDA, TFT_SCK, TFT_RST);
const float offset = 0;
const float vt_factor = 1; //1.35 alt 1.4
const int Regler = 38;
const int CLK = 39;
const int Start = 26;
float temp_c1;
float temp_c2;
float temp_c3;
int Temperatur1 = 35;
int Temperatur2 = A0;
int Temperatur3 = A0;
int y;
int Zustand = 0;
int zealer = 0;
int counter = 200;
unsigned long last_run = 0;
void setup() {
pinMode(Regler, INPUT);
pinMode (LED_BUILTIN, OUTPUT);
pinMode(Temperatur1, INPUT);
pinMode(Temperatur2, INPUT);
pinMode(Temperatur3, INPUT);
Serial.begin (115200);
attachInterrupt(digitalPinToInterrupt(CLK), shaft_moved, FALLING);
tft.begin();
//tft.fillScreen(ILI9341_BLACK);
tft.setRotation(3);
xTaskCreatePinnedToCore (
loop2, // Function to implement the task
"loop2", // Name of the task
4096, // Stack size in words
NULL, // Task input parameter
0, // Priority of the task
NULL, // Task handle.
0 // Core where the task should run
);
xTaskCreatePinnedToCore (
loop4, // Function to implement the task
"loop4", // Name of the task
4096, // Stack size in words
NULL, // Task input parameter
1, // Priority of the task
NULL, // Task handle.
1 // Core where the task should run
);
}
void clearTextArea(int x, int y, int width, int height) {
tft.fillRect(x, y, width, height, ILI9341_BLACK); // Hintergrundfarbe
}
ICACHE_RAM_ATTR void shaft_moved() {
if (millis() - last_run > 5) {
if (digitalRead(Regler) == LOW) {
counter++;
if (counter > 400) counter = 400;
}
if (digitalRead(Regler) == HIGH) {
counter--;
if (counter < 200) counter = 200;
}
last_run = millis();
}
}
// the loop function runs over and over again forever
void loop() {
Serial.println(temp_c1);
Serial.println(counter);
//clearTextArea(20, 120, 200, 39);
//clearTextArea(20, 180, 400, 30);
// tft.pushColor(ILI9341_GREEN);
// tft.clearScreen();
tft.setCursor(20, 120);
// tft.setTextColor(ILI9341_RED);
tft.setTextColor(ILI9341_RED, ILI9341_BLACK);
tft.setTextSize(3);
tft.print(temp_c1);
tft.setCursor(20, 180);
tft.print("Soll Temp.: "); tft.print(counter); tft.print((char)247); tft.println("C");
}
// the loop2 function also runs forver but as a parallel task
void loop2 (void* pvParameters) {
Serial.print (" World from loop2() at ");
Serial.println (xPortGetCoreID());
while (1) {
int T1 = analogRead(Temperatur1);
temp_c1 = ((T1 / vt_factor) + offset);
}
}
void loop4 (void* pvParameters) {
Serial.print (" World from loop4() at ");
Serial.println (xPortGetCoreID());
while (1) {
delay (500); // wait for half a second
delay (500); // wait for half a second
}
}