/*
ESP32 HTTPClient Jokes API Example
https://wokwi.com/projects/342032431249883731
Copyright (C) 2022, Uri Shaked
*/
//#include <WiFi.h>
#include "HX711.h"
#include <EncButton.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
//const char* ssid = "Wokwi-GUEST";
//const char* password = "";
#define PERIOD_1 5000
#define BTN_PIN 5
#define TFT_DC 2
#define TFT_CS 15
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
EncButton enc(25, 26, 5);
HX711 scale;
float mass = 0;
unsigned long timer_1;
bool btnFlag =false;
uint8_t mSelect=0;
uint8_t UmSelect;
int timeMins=60;
int timeSecs=0;
void Menu() {
tft.fillRoundRect(0, 44, 320, 28, 5, 0x540); // Start MASS
tft.setTextColor(0x540);
tft.setTextSize(1);
tft.setTextWrap(false);
tft.setCursor(19, 8);
tft.print("Start MASS");
tft.drawRoundRect(0, 0, 101, 42, 2, 0xAD55); // START
tft.setTextColor(0x0);
tft.setTextSize(3);
tft.setCursor(116, 48);
tft.print("START");
tft.setTextSize(2);
tft.setCursor(8, 22);
tft.print(mass);
tft.drawRoundRect(102, 0, 116, 42, 4, 0x540); //TAIMER
tft.drawRoundRect(219, 0, 101, 42, 2, 0xAD55);
tft.setTextColor(0xFFFF);
tft.setTextSize(2);
tft.setCursor(124, 2);
tft.print("TAIMER");
tft.setTextSize(3);
tft.setCursor(116, 19);
tft.print(mSelect);
tft.setTextColor(0x540); // EndMass
tft.setTextSize(1);
tft.setCursor(248, 8);
tft.print("EndMass");
tft.setTextSize(2);
tft.setCursor(227, 22);
tft.print("1000.11");
tft.drawRoundRect(0, 74, 319, 71, 2, 0x52AA); //diagram
tft.drawLine(1, 86, 317, 98, 0x57EA);
tft.fillRoundRect(4, 150, 44, 20, 4, 0x540); // PLA
tft.setTextColor(0x0);
tft.setCursor(9, 153);
tft.print("PLA");
tft.drawRoundRect(0, 198, 319, 41, 2, 0x52AA); // Lenght Filament
tft.setTextColor(0x540); // Lenght Filament
tft.setCursor(5, 216);
tft.print("Lenght Filament");
tft.setTextSize(3);
tft.setCursor(189, 209);
tft.print("100.5");
tft.setTextSize(1);
tft.setCursor(284, 223);
tft.print("Metrs");
tft.drawRoundRect(51, 150, 44, 20, 4, 0x540);
tft.setTextSize(2);
tft.setCursor(56, 153);
tft.print("ABS");
tft.drawRoundRect(97, 150, 44, 20, 4, 0x540);
tft.setCursor(102, 153);
tft.print("SBS");
tft.drawRoundRect(143, 150, 44, 20, 4, 0x540);
tft.setCursor(148, 153);
tft.print("TPU");
tft.drawRoundRect(189, 150, 55, 20, 4, 0x540);
tft.setCursor(194, 153);
tft.print("PETG");
tft.drawRoundRect(247, 150, 56, 20, 4, 0x540);
tft.setCursor(252, 153);
tft.print("FLEX");
tft.drawRoundRect(4, 173, 78, 20, 4, 0x540);
tft.setCursor(8, 176);
tft.print("NYLON");
tft.drawRoundRect(0, 147, 319, 49, 2, 0x52AA);
//--------
tft.drawRoundRect(0, 147, 319, 49, 2, 0x52AA); // rect filament
tft.fillRoundRect(123, 190, 82, 13, 3, 0x52AA); // rect colibraton
tft.setTextColor(0x0);
tft.setTextSize(1);
tft.setCursor(134, 193);
tft.print("colibraton");
tft.setTextColor(0xFFFF); // temperatur
tft.setTextSize(2);
tft.setCursor(305, 179);
tft.print("C");
tft.setCursor(269, 179);
tft.print("+25");
tft.setCursor(256, 179);
tft.print("t");
}
void taimer() {
if(mSelect==0) {
tft.setTextColor(0xFFFF);
tft.setTextSize(3);
tft.setCursor(116, 19);
tft.println(timeMins);
}else{
tft.setTextColor(0xAD55);
tft.setTextSize(3);
tft.setCursor(116, 19);
tft.println(timeMins);
}
}
void StartMass() {
tft.setTextColor(0x540);
tft.setTextSize(2);
tft.setCursor(8, 22);
tft.print(mass);
}
void EndMass() {}
void StartBtn() {
if(mSelect==1) {
tft.fillRoundRect(0, 44, 320, 28, 5, 0x0);
tft.drawRoundRect(0, 44, 320, 28, 5, 0xFFFF); // START select
tft.setTextColor(0xFFFF);
tft.setTextSize(3);
tft.setCursor(116, 48);
tft.print("START");
} else{
tft.fillRoundRect(0, 44, 320, 28, 5, 0x540); // START
tft.setTextColor(0x0);
tft.setTextSize(3);
tft.setCursor(116, 48);
tft.print("START");
}
}
void filament() {
if(mSelect==2) {
tft.drawRoundRect(0, 147, 319, 49, 2, 0xFFFF); // rect filament select
tft.fillRoundRect(123, 190, 82, 13, 3, 0x52AA); // rect colibraton
tft.setTextColor(0x0);
tft.setTextSize(1);
tft.setCursor(134, 193);
tft.print("colibraton");
} else{
tft.drawRoundRect(0, 147, 319, 49, 2, 0x52AA); // rect filament
tft.fillRoundRect(123, 190, 82, 13, 3, 0x52AA); // rect colibraton
tft.setTextColor(0x0);
tft.setTextSize(1);
tft.setCursor(134, 193);
tft.print("colibraton");
}
}
void colibration() {
if(mSelect==3) {
tft.fillRoundRect(123, 190, 82, 13, 3, 0xFFFF); // rect colibraton select
tft.setTextColor(0x0);
tft.setTextSize(1);
tft.setCursor(134, 193);
tft.print("colibraton");
} else{
tft.fillRoundRect(123, 190, 82, 13, 3, 0x52AA); // rect colibraton
tft.setTextColor(0x0);
tft.setTextSize(1);
tft.setCursor(134, 193);
tft.print("colibraton");
}
}
void setup() {
pinMode(BTN_PIN, INPUT_PULLUP);
tft.begin();
tft.setRotation(1);
scale.begin(14, 12);
Menu();
}
void loop() {
if (digitalRead(BTN_PIN) == LOW && btnFlag == false) {
btnFlag=true;
} else {
btnFlag=false;
}
tft.setTextColor(0x52AA);
tft.setTextSize(2);
tft.setCursor(1, 2);
tft.print(btnFlag);
if (millis() - timer_1 > PERIOD_1) { // условие таймера
timer_1 = millis(); // сброс таймера
tft.setTextColor(0x0);
tft.setTextSize(2);
tft.setCursor(8, 22);
tft.print(mass); // выполняем блок №1 каждые PERIOD_1 миллисекунд
mass=scale.read_average(5);
StartMass();
}
enc.tick();
if (enc.right()) {
tft.setTextColor(0x0);
tft.setTextSize(3);
tft.setCursor(116, 19);
tft.print(mSelect);
if (btnFlag == false) mSelect++;
if (mSelect>3) mSelect=0;
if (btnFlag == true && mSelect==0) timeMins=timeMins+5;
taimer();
StartBtn();
filament();
colibration();
}
if (enc.left()) {
tft.setTextColor(0x0);
tft.setTextSize(3);
tft.setCursor(116, 19);
tft.print(mSelect);
if (btnFlag == false) mSelect--;
if (mSelect==255) mSelect=3;
if (btnFlag == true && mSelect==0) timeMins=timeMins-5;
taimer();
StartBtn();
filament();
colibration();
}
}