#include "Free_Fonts.h"
#include <TFT_eSPI.h>
#include <SPI.h> // this is needed for display
#include "spy-1.h"
#include "font.h"
// The display also uses hardware SPI, plus #9 & #10
#define TFT_CS 15
#define TFT_DC 2
#define TFT_MOSI 23
#define TFT_SCLK 18
#define open_button 5
#define BLUE_REC 0x251F
float dispTemp = 22.3;
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library with default width and height
TFT_eSprite img = TFT_eSprite(&tft);
void test(){
tft.startWrite();
tft.setAddrWindow(85,263,80,263);
for(int16_t i = 0; i < 33; i+=2) {
tft.pushColor(TFT_WHITE, 5*1); // push dash pixels
tft.pushColor(TFT_BLACK, 5*1); // push gap pixels
}
tft.endWrite();
}
void drawDashedLine(uint16_t x, uint16_t y, uint16_t w, uint16_t h){
uint16_t dash_h = 1;
uint16_t dash_w = 5;
tft.setAddrWindow(x,y,w,h);
uint8_t dash_n = (x+w) / dash_w;
for(uint16_t i = 0;i < dash_n; i+=2){
tft.pushColor(TFT_WHITE, dash_w*dash_h); // push dash pixels
tft.pushColor(TFT_BLACK, dash_w*dash_h); // push gap pixels
}
}
void updateValue(int x, int y,String value){
img.setColorDepth(8);
img.createSprite(80, 20);
img.setFreeFont(&Roboto_Condensed_Light_16);
img.fillSprite(TFT_BLACK);
img.drawString(String(value),0,0);
img.pushSprite(x, y, TFT_TRANSPARENT);
img.deleteSprite();
}
void removeText(int x, int y){
img.setColorDepth(8);
img.createSprite(80, 20);
img.fillSprite(TFT_BLACK);
img.pushSprite(x, y);
img.deleteSprite();
}
void setup(void) {
Serial.begin(115200);
tft.begin();
tft.setRotation(0);
// themeClockTFT(dispTemp, "TEMP", "`C", "88.8", "temp", 1);
// Fill screen and setSwapBytes
// tft.fillScreen(TFT_BLACK);
tft.setSwapBytes(true);
// tft.setColorDepth(8);
// Spy Image
tft.pushImage(0,0,240,240,spy);
// RGB box
tft.fillRect(0,240,80,23,BLUE_REC);
tft.fillRect(0,268,80,23,TFT_RED);
tft.fillRect(0,296,80,24,TFT_GREEN);
// Dashed Line
drawDashedLine(85,263,80,263);
drawDashedLine(85,293,80,293);
// test();
// Draw font in three box
tft.setFreeFont(&Roboto_Condensed_Light_16); //set Font
tft.setTextColor(TFT_WHITE,BLUE_REC); // Set text color, text background
tft.drawString("Status",2,245);
// tft.drawString("Undetected",85,245);
tft.setTextColor(TFT_WHITE,TFT_RED);
tft.drawString("Distance",2,273);
tft.setTextColor(TFT_WHITE,TFT_GREEN);
tft.drawString("Date",2,301);
tft.setTextColor(TFT_WHITE);
pinMode(5, INPUT_PULLUP);
}
int prev_state = 0;
int curr_state = 0;
bool on_state = true;
bool prev_on = false;
void loop() {
curr_state = digitalRead(open_button);
if(prev_state==LOW && curr_state==HIGH){
on_state = !on_state;
}
if(on_state == true){
if(dispTemp <10){
updateValue(85,240,String("Detected"));
}
else{updateValue(85,240,String("Undetected"));}
updateValue(85,274,String(dispTemp));
}
if(on_state == false){
if(prev_on == on_state){}
else{
tft.fillRect(85,240,80,20,TFT_BLACK);
tft.drawString("off", 85,245);
}
}
dispTemp--;
if(dispTemp<0){dispTemp=20;}
prev_state = curr_state;
prev_on = on_state;
Serial.println(on_state);
delay(100);
}
// void themeClockTFT(float value, const String& lable, const String& units, const String& valueSample, const String& valueType, unsigned int accuracy) {
// int xpos = 10;
// int ypos = 45;
// int yPad = 0;
// int padding = tft.textWidth(String(value, accuracy), FONT8);
// tft.setTextDatum(TL_DATUM);
// tft.drawString(lable, xpos, ypos, FONT4);
// tft.setTextDatum(TR_DATUM);
// tft.drawString(units, 240 - xpos, ypos, FONT4);
// tft.setTextDatum(TL_DATUM);
// tft.setTextPadding(padding);
// ypos += tft.fontHeight(FONT8) / 2 + yPad;
// tft.drawFloat(value, accuracy, (240 - padding) / 2, ypos, FONT8);
// tft.setTextPadding(0);
// }
Loading
ili9341-cap-touch
ili9341-cap-touch