int LED_BUILTIN = 33;
#include <Wire.h>
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#define TFT_DC 2
#define TFT_CS 15
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
const float offset = 0;
const float vt_factor = 1.4; //1.35
const int Regler = 0;
const int CLK = 32;
const int Start = 26;
float temp_c1;
float temp_c2;
float temp_c3;
int Temperatur1 = 34;
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.setRotation(3);
xTaskCreatePinnedToCore (
loop2, // Function to implement the task
"loop2", // Name of the task
1000, // Stack size in words
NULL, // Task input parameter
0, // Priority of the task
NULL, // Task handle.
0 // Core where the task should run
);
xTaskCreatePinnedToCore (
test, // Function to implement the task
"test", // Name of the task
1000, // Stack size in words
NULL, // Task input parameter
1, // Priority of the task
NULL, // Task handle.
1 // Core where the task should run
);
xTaskCreatePinnedToCore (
loop4, // Function to implement the task
"loop4", // Name of the task
1000, // 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(zealer);
Serial.println(counter);
clearTextArea(20, 120, 200, 39);
clearTextArea(20, 180, 400, 30);
tft.setCursor(20, 120);
tft.setTextColor(ILI9341_RED);
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");
Serial.println (xPortGetCoreID());
}
// the loop2 function also runs forver but as a parallel task
void loop2 (void* pvParameters) {
while (1) {
int T1 = analogRead(Temperatur1);
temp_c1 = ((T1 / vt_factor) + offset);
Serial.print ("Hello");
Serial.print (" World from loop2() at ");
Serial.println (xPortGetCoreID());
}
}
void test (void* pvParameters) {
while (1) {
}
}
void loop4 (void* pvParameters) {
while (1) {
Serial.print ("Hello");
delay (500); // wait for half a second
Serial.print (" World from loop4() at ");
Serial.println (xPortGetCoreID());
delay (500); // wait for half a second
}
}