/*
Simple "Hello World" for ILI9341 LCD
https://wokwi.com/arduino/projects/308024602434470466
*/
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
int potpin = 0; // analog pin used to connect the potentiometer
int t; // variable to read the value from the analog pin
#define TFT_DC 9
#define TFT_CS 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
#define COLOR(r, g, b) ((((r) & 0x1F) << 11) | (((g) & 0x3F) << 5) | ((b) & 0x1F))
void setup() {
Serial.begin(115200);
tft.begin();
Serial.println("готов");
/*tft.setCursor(26, 120);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(3);
tft.println("Hello, TFT!");*/
/*int color = tft.color565(map(val,0,1023,0,255),255,10);
tft.setCursor(0,0);
tft.fillRect(0,0,240,50,color);
tft.drawRect(0,0,240,50,0xFFFF);*/
// Meme reference: https://english.stackexchange.com/questions/20356/origin-of-i-can-haz
}
void loop() {
//t = map(analogRead(potpin),0,1023,-40,40);
if (Serial.available() > 0) {
String buf = Serial.readString();
t = buf.toInt();
}
// int16_t color = tft.color565(map(val,-40,40,0,255),map(val,-40,40,0,7),map(val,-40,40,255,159));
tft.setCursor(0,0);
//tft.fillScreen(ColorFromTemp(val));
//tft.drawRect(0,0,240,50,0xFFFF);
//tft.fillScreen(tft.color565(255,0,val));
Serial.println(t);
if (t < -10)
{tft.fillScreen(ILI9341_BLUE);}
else if (t < 0)
{tft.fillScreen(0x035F);}
else if (t < 10)
{tft.fillScreen(ILI9341_WHITE);}
else if (t < 18)
{tft.fillScreen(0x07FA);}
else if (t < 27)
{tft.fillScreen(ILI9341_GREEN);}
else if (t < 32)
{tft.fillScreen(ILI9341_YELLOW);}
else if ( t < 36)
{tft.fillScreen(ILI9341_ORANGE);}
else if (t > 35)
{tft.fillScreen(ILI9341_RED);}
delay(10);
}
/* uint16_t ColorFromTemp(int temp)
{
if(temp < -10)
temp = -10;
else if(temp > 22)
temp = 22;
temp += 10;
int r = temp;
int g = 0;//20-temp;
int b = 31 - temp;
Serial.print("r= ");Serial.println(r);
Serial.print("g= ");Serial.println(g);
Serial.print("b= ");Serial.println(b);
return COLOR(r, g, b);
}*/