// ESP32_ILI9341_openweathermap
// downloads json string from openweather.com
// for environmental conditions of (any) town
// displays alphanumerically, with gauges and with icons
//
// updates every five minutes in Loop - check the variable named timerDelay
//
// microcontroller ESP32-WROOM-32
// current display TFT 018 = 320*240 ILI9341 controller
// implements Bodmer's TFT_ESPI library
// implements Bodmer's rainbow scale gauge
//
// json instructions by Rui Santos
// at https://RandomNerdTutorials.com/esp32-http-get-open-weather-map-thingspeak-arduino/
//
// public domain
// July 6, 2021 - minor issues fixed, compass pointer fixed
// Floris Wouterlood
//
// Make sure all the display driver and pin conections are correct by
// editing the User_Setup.h file in the TFT_eSPI library folder.
//
// ######################################################################################
// ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE TFT_eSPI LIBRARY #####
// ######################################################################################
#include <TFT_eSPI.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <Arduino_JSON.h>
#include "Free_Fonts.h" // include the header file attached to this sketch - part of TFT_eSPI package
TFT_eSPI tft = TFT_eSPI();
TFT_eSprite sprite1 = TFT_eSprite(&tft);
#define WHITE 0xFFFF
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define GREY 0x2108
#define SCALE0 0xC655 // accent color for unused scale segments
#define SCALE1 0x5DEE // accent color for unused scale segments
#define TEXT_COLOR 0xFFFF // is currently white
int32_t xC = 160, yC = 110; //souřad středu
int32_t irad = 85, orad = 95;
uint32_t startAngle=175, endAngle=185;
uint32_t fg_color=TFT_ORANGE, bg_color=TFT_ORANGE;
//uint32_t DarkGrey = 0x1A1A1A; //definice tmavé šedé
//#define CeHn (0, 191, 255)
const int HodnPotPin = A6; //Analog Pin ADC6 = A6 = G34
int HodnPot;
int HodnBar;
float Voltage;
float Current;
int Cas;
void setup() {
Serial.begin(115200);
tft.begin();
tft.setRotation(1);
tft.fillScreen(TFT_BLACK);
sprite1.createSprite(320, 20); //velikost sprite
//
}
void loop() {
HodnPot = analogRead(HodnPotPin);
HodnBar = map(HodnPot, 0, 4095, -90, 90);
Voltage = map(HodnPot, 0, 4095, 0, 430.0);
Current = map(HodnPot, 0, 4095, 0, 2000);
Cas = map(HodnPot, 0, 4095, 500, 2500);
// sprite1.fillSprite(TFT_BLACK); //?????
// tft.drawArc(xC, yC, orad, irad, 85, 275, DarkGrey, DarkGrey, true); //hranaté okraje
// sprite1.drawSmoothArc(xC, yC, orad, irad, 85, 275, TFT_BLACK, TFT_YELLOW, true); //podklad první vnitřek, druhý okraj Dělá jen žlutý obrys
// sprite1.drawSmoothArc(xC, yC, orad, irad, 85, 275, TFT_DARKGREY, TFT_DARKGREY, true);
// sprite1.drawSmoothArc(xC, yC, orad, irad, startAngle+HodnBar, endAngle+HodnBar, fg_color, bg_color, true); //běžec
sprite1.fillRect(260, 2, 43, 10, TFT_BLACK); //
sprite1.fillRect(260, 2, Voltage/10, 10, TFT_WHITE);
sprite1.drawRect(260, 2, 43, 10, TFT_WHITE); //okraj obdélníka
sprite1.fillRect(303, 4, 4, 6, TFT_WHITE); //okraj obdélníka
sprite1.pushSprite(0, 0); //umístění sprite
tft.setTextColor(TFT_DARKGREY, TFT_BLACK);
char bufferA [10];
sprintf (bufferA, "U=%.2fV Umin=%.2fV ", Voltage, Voltage+10);
tft.drawString(String(bufferA), 0, 135, 4);
tft.setTextColor(TFT_DARKGREY, TFT_BLACK);
char bufferB [10];
sprintf (bufferB, "I=%.1fmA Imax=%.1fmA ", Current, Current+20);
tft.drawString(String(bufferB), 0, 160, 4);
tft.setTextColor(TFT_LIGHTGREY, TFT_BLACK);
char bufferP [10];
sprintf (bufferP, "P=%3dmW ", Voltage+20);
tft.drawString(String(bufferP), 0, 185, 4);
tft.setTextColor(TFT_GREEN, TFT_BLACK);
char bufferC [5]; //zobrazení dat z bufferu
sprintf (bufferC, "%3d ", HodnBar);
tft.drawString(String(bufferC), 200, 40, 7); //font 7 - sedmisegmentovky
tft.setTextColor(TFT_YELLOW, TFT_BLACK);
char bufferD [7]; //zobrazení dat z bufferu
sprintf (bufferD, "%4dus ", Cas);
tft.drawString(String(bufferD), 210, 100, 4);
Serial.print(Voltage);
Serial.print(" ");
Serial.println(Current);
}