/*
Simple "Hello World" for ILI9341 LCD
https://wokwi.com/arduino/projects/308024602434470466
*/
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "colors.h"
#include <Fonts/FreeSansBold9pt7b.h>
#include <Fonts/FreeSans9pt7b.h>
#define fontHeader &FreeSansBold9pt7b
#define fontText &FreeSans9pt7b
#define fontTextBold &FreeSansBold9pt7b
#define TFT_DC 9
#define TFT_CS 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
uint16_t colorBattery;
uint16_t colorBorder = ILI9341_WHITE;
uint16_t colorBackground = ILI9341_BLACK;
int outbackFNDC_I_Out = 200;
int outbackFNDC_I_In = 100 ;
int OwnConsumedPower = 1800;
int GridConsumedPower = 799;
uint16_t colorText = ILI9341_WHITE;
uint16_t colorHouse = ILI9341_ORANGE;
void setup() {
tft.begin();
tft.setRotation(3);
//displayAnimations();
int w = 8;
int rx = 160;
int ry = 100;
//displayPower(30, 30, 0, 4600, 1200);
//displayPowerLines();
// use 50/50 for the size of the house with Graphs in it (aka displayMyVilla not displayMyVilla2)
//displayMyVilla(70, 180, 25, 55, colorBorder, colorHouse, colorBackground);
//displayMyVilla2(80, 180, 25, 40, colorBorder, colorHouse, colorBackground);
// for (int n = 0; n < 5; n++) {
//// tft.fillArc(160, 100, 300, 40, rx-n*w, ry-n*w, w, 31-n*6);
//}
//displayText(60, 60, "2.1kW", 2, colorHouse, colorText);
// displayRuler();
//displayBattery(58, 102);
displayPowerMeter(30, 30, 0, 4600, 2300, true, true);
tft.setCursor(26, 120);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(3);
//tft.println("Hello, TFT!");
tft.setCursor(20, 160);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(2);
//tft.println("I can has colors?");
// Meme reference: https://english.stackexchange.com/questions/20356/origin-of-i-can-haz
}
void displayMyVilla(int posX, int posY, int height, int width, uint16_t colorBorder, uint16_t colorForeground, uint16_t colorBackground) {
int x0 = posX;
int y0 = posY + height;
int x1 = posX + width;
int y1 = posY + height;
int x2 = posX + width / 2;
int y2 = posY;
//Draw the Lawn
tft.fillCircle(posX + 7, posY + height*2+height/2, 20, ILI9341_DARKGREEN);
tft.fillCircle(posX + width - 5, posY + height*2+height/2, 20, ILI9341_DARKGREEN);
tft.fillRect(posX, posY + height*2, width , height, ILI9341_DARKGREEN);
tft.fillTriangle(x0, y0, x1 + 1, y1, x0 + width/2, y2, colorForeground);
tft.drawTriangle(x0, y0, x1 + 1, y1, x0 + width/2, y2, colorBackground);
tft.fillRoundRect(x0 + 3, y0 + 2, width - 4, height + 2, 2, colorForeground);
//tft.fillRountRect
//tft.fill
}
void displayText(int posX, int posY, char displayText[], int size, uint16_t boxColor, uint16_t textColor) {
int radius = 5;
int boxLength = 5 * 14;
int boxHeight = 20;
colorBackground = ILI9341_BLUE;
uint16_t colorShadow = boxColor - 300;
tft.fillRoundRect(posX - 2, posY + 2, boxLength, boxHeight, radius, colorShadow); //Background Box
tft.drawRoundRect(posX - 2, posY + 2, boxLength, boxHeight, radius, colorShadow - 100);
tft.fillRoundRect(posX, posY, boxLength, boxHeight, radius, boxColor); // text box
tft.drawRoundRect(posX, posY, boxLength, boxHeight, radius, colorBorder);
printTextToTFT(colorText, 2, posX + 4, posY + 2, true, displayText);
//char buff[10];
//sprintf(buff,"Length is %d",boxLength);
//printTextToTFT(colorText, 2, posX+2,posY+50,true,buff);
}
void displayMyVilla2(int posX, int posY, int height, int width, uint16_t colorBorder, uint16_t colorForeground, uint16_t colorBackground) {
int x0 = posX;
int y0 = posY + height;
int x1 = posX + width;
int y1 = posY + height;
int x2 = posX + width / 2;
int y2 = posY;
/*
X0 start for grass
y0 +width = start for grass
*/
tft.fillCircle(x0 + 7, y0 + width, 20, ILI9341_DARKGREEN);
tft.fillCircle(x1 + width - 5, y0 + width, 20, ILI9341_DARKGREEN);
tft.fillRect(x0, y0 + width, width * 2, height, ILI9341_DARKGREEN);
//Draw Trailing Roof First so leading edge is overwritten
tft.fillTriangle(x0 + width, y0, x1 + width + 1, y1, x2 + width, y2, colorForeground);
tft.drawTriangle(x0 + width, y0, x1 + width + 1, y1, x2 + width, y2, colorBackground);
//fill the roof next
tft.fillRoundRect(x2, y2 + 2, width - 4, height - 2, 2, colorForeground);
tft.fillRoundRect(x2 - 1, y2, width, height - 2, 2, colorForeground); //Roof Coloring
tft.drawLine(x2, y2, x2 + width - 2, y2, colorBackground);
tft.drawLine(x1, y1, x2 + width - 1, y1, colorBackground); //Vertical Wall Post
//Draw Leading roof Last so 3D effect
tft.fillTriangle(x0, y0, x1, y1, x2, y2, colorForeground);
tft.drawTriangle(x0, y0, x1, y1, x2, y2, colorBackground);
//Draw the base of the house
tft.fillRoundRect(x0 + 3, y0, width * 2 - 4, height, 2, colorForeground);
tft.drawRoundRect(x0 + 3, y0, width * 2 - 4, height, 2, colorBackground);
tft.drawLine(x1, y1, x1, y1 + height, colorBackground); //Vertial Line of the wall
tft.drawRoundRect(x1 - 15, y0 + height - 15, 8, 15, 2, colorBackground); //draw the door
printTextToTFT(colorText, 1, x1 + 6, y1 + 2, true, "2.9kW", fontText);
}
void displayHouse() {
uint16_t colorHouse = ILI9341_ORANGE;
uint16_t colorBorder = ILI9341_WHITE;
int centerX = 100;
int centerY = 155;
//int iconSize = 64;
int x1 = centerX - 5; // Left
int y1 = centerY + 40;
int x2 = centerX + 65; // Right
int y2 = centerY + 40;
int x3 = centerX + 30; // Apex
int y3 = centerY + 10;
//int x = 100;
//int y = 160;
char buff1[9];
float housePower = 0.0;
housePower = GridConsumedPower + OwnConsumedPower; // this is because the SDM230 sees all the power Request / both excess (gridConsumed) and oneConsumed
if (housePower < 2900 && GridConsumedPower < 100) { // Need to extend this to the night time AND Daytime for low power consumption Mode warnings
colorHouse = ILI9341_GREEN;
} else if (housePower < 5000 || GridConsumedPower > 100) {
colorHouse = ILI9341_ORANGE;
} else if (housePower > 5000 || GridConsumedPower > 1000) {
colorHouse = ILI9341_RED;
}
if (housePower > 1000) {
dtostrf(housePower / 1000, 3, 1, buff1);
sprintf(buff1, "%skW", buff1);
} else {
dtostrf(housePower, 3, 0, buff1);
sprintf(buff1, "%sW", buff1);
}
displayMyVilla(80, 180, 25, 40, colorBorder, colorHouse, colorBackground);
printTextToTFT(colorText, 2, x1 + 6, y1 + 2, true, buff1);
//tft.drawCircle(x1 + 5 + ((x2 - x1) / 2) + 5, y1 + 15 + 10, 1, ILI9341_WHEAT); //draw the door knob
}
void displayMyVillaO(int posX, int posY, int height, int width, uint16_t colorBorder, uint16_t colorForeground, uint16_t colorBackground) {
int x0 = posX;
int y0 = posY + height;
int x1 = posX + width;
int y1 = posY + height;
int x2 = posX + width / 2;
int y2 = posY;
//Draw the Lawn
tft.fillCircle(x0 + 7, y0 + width, 20, ILI9341_DARKGREEN);
tft.fillCircle(x1 + width - 5, y0 + width, 20, ILI9341_DARKGREEN);
tft.fillRect(x0, y0 + height, width * 2, height, ILI9341_DARKGREEN);
//Draw Trailing Roof First so leading edge is overwritten
tft.fillTriangle(x0 + width, y0, x1 + width + 1, y1, x2 + width, y2, colorForeground);
tft.drawTriangle(x0 + width, y0, x1 + width + 1, y1, x2 + width, y2, colorBackground);
//fill the roof next
tft.fillRoundRect(x2, y2 + 2, width - 4, height - 2, 2, colorForeground);
tft.fillRoundRect(x2 - 1, y2, width, height - 2, 2, colorForeground); //Roof Coloring
tft.drawLine(x2, y2, x2 + width - 2, y2, colorBackground);
tft.drawLine(x1, y1, x2 + width - 1, y1, colorBackground); //Vertical Wall Post
//Draw Leading roof Last so 3D effect
tft.fillTriangle(x0, y0, x1, y1, x2, y2, colorForeground);
tft.drawTriangle(x0, y0, x1, y1, x2, y2, colorBackground);
//Draw the base of the house
tft.fillRoundRect(x0 + 3, y0, width * 2 - 4, height, 2, colorForeground);
tft.drawRoundRect(x0 + 3, y0, width * 2 - 4, height, 2, colorBackground);
tft.drawLine(x1, y1, x1, y1 + height, colorBackground); //Vertial Line of the wall
tft.drawRoundRect(x1 - 15, y0 + height - 15, 8, 15, 2, colorBackground); //draw the door
printTextToTFT(colorText, 2, x1 + 6, y1 + 2, true, "2.1kW", fontText);
}
void displayPowerLines() {
int startX = 158;
int startY = 222;
int bendX = -50;
int bendY = 0;
int endX = 0;
int endY = 40;
int toBend = 10;
int lineLength = 52;
int lineWidth = 30;
int outbackLineLength = 69;
int batteryStartX = 70;
int batteryStartY = 148;
int batteryEndX = batteryStartX + 50;
int batteryEndY = batteryStartY ;
uint16_t colorKostalLines = ILI9341_CYAN;
uint16_t colorOutbackLines = ILI9341_CYAN;
uint16_t colorBatteryLines = ILI9341_RED;
if (OwnConsumedPower > 0) {
colorKostalLines = ILI9341_GREEN;
}
if (GridConsumedPower > 0) {
colorOutbackLines = ILI9341_RED;
}
if (outbackFNDC_I_In > outbackFNDC_I_Out * -1) {
colorBatteryLines = ILI9341_GREEN;
}
tft.drawLine(startX, startY, startX + toBend, startY, colorKostalLines);
tft.drawLine(startX, startY + 1, startX + toBend + 1, startY + 1, colorKostalLines); // from house
tft.drawLine(startX + toBend, startY, startX + toBend, startY - lineLength, colorKostalLines); // Line up
tft.drawLine(startX + toBend + 1, startY, startX + toBend + 1, startY - lineLength, colorKostalLines);
tft.drawLine(startX + toBend, startY - lineLength, startX + toBend + lineWidth, startY - lineLength, colorKostalLines); //lineWidth
tft.drawLine(startX + toBend, startY - lineLength + 1, startX + toBend + lineWidth + 1, startY - lineLength + 1, colorKostalLines);
tft.drawLine(startX + toBend + lineWidth, startY - lineLength, startX + toBend + lineWidth, startY - lineLength - toBend, colorKostalLines); //toKostal
tft.drawLine(startX + toBend + lineWidth + 1, startY - lineLength, startX + toBend + lineWidth + 1, startY - lineLength - toBend, colorKostalLines);
tft.drawLine(startX, startY - 5, startX + toBend / 2, startY - 5, colorOutbackLines); // Outback Lines
tft.drawLine(startX, startY - 6, startX + toBend / 2 + 1, startY - 6, colorOutbackLines);
tft.drawLine(startX + toBend / 2, startY - 5, startX + toBend / 2, startY - 5 - outbackLineLength, colorOutbackLines);
tft.drawLine(startX + toBend / 2 + 1, startY - 5, startX + toBend / 2 + 1, startY - 5 - outbackLineLength, colorOutbackLines);
tft.drawLine(batteryStartX, batteryStartY, batteryStartX, batteryStartY + toBend / 2, colorBatteryLines); //Battery Lines
tft.drawLine(batteryStartX - 1, batteryStartY, batteryStartX - 1, batteryStartY + toBend / 2 + 1, colorBatteryLines);
tft.drawLine(batteryStartX, batteryStartY + toBend / 2, batteryEndX, batteryEndY + toBend / 2, colorBatteryLines);
tft.drawLine(batteryStartX - 1, batteryStartY + toBend / 2 + 1, batteryEndX, batteryEndY + toBend / 2 + 1, colorBatteryLines);
tft.drawLine(batteryEndX, batteryEndY + toBend / 2, batteryEndX, batteryStartY - 1, colorBatteryLines);
tft.drawLine(batteryEndX + 1, batteryEndY + toBend / 2 + 1, batteryEndX + 1, batteryStartY - 1, colorBatteryLines);
}
void displayRuler() {
int X = 320;
int Y = 240;
tft.drawLine(X / 2, 0, X / 2, Y, colorBorder); //vertical
tft.drawLine(0, Y / 2, X, Y / 2, colorBorder); //horizontal
for (int x = 0; x <= X; x = x + 10) {
tft.drawLine(x, Y / 2 - 5, x, Y / 2 + 5, colorBorder);
}
for (int x = 0; x <= Y; x = x + 10) {
tft.drawLine(X / 2 - 5, x, X / 2 + 5, x, colorBorder);
}
}
void displayBatteryPowerLines(int posX, int posY) {
int width = 56; // Width of the Battery
int height = 45; // Height of the Battery
int batteryLineLength = 23;
uint16_t flowColor = ILI9341_RED;
if (outbackFNDC_I_In > outbackFNDC_I_Out * -1) {
flowColor = ILI9341_GREEN;
}
int lineY = posY + (height * 0.80);
tft.drawLine(posX + width + 1, lineY - 2, posX + width + 1 + batteryLineLength, lineY - 2, colorBorder);
tft.drawLine(posX + width + 1, lineY - 1, posX + width + 1 + batteryLineLength, lineY - 1, flowColor);
tft.drawLine(posX + width + 1, lineY + 0, posX + width + 1 + batteryLineLength, lineY + 0, flowColor);
tft.drawLine(posX + width + 1, lineY + 1, posX + width + 1 + batteryLineLength, lineY + 1, colorBorder);
}
void displayPowerGraph(int posX, int posY, int valueMin, int valueMax, int value) {
int barLength = 20;
int barWidth = 5;
int barGap = 0;
int graphSegments = 17;
int mapValue;
int rectRadius = 0;
uint16_t colorStep;
uint16_t colorStart = 0x001F;
uint16_t colorEnd = 0xF800;
tft.drawRoundRect(posX - 2, posY - 1, (barWidth + barGap) * graphSegments + 3, barLength + 2, 1, colorBorder);
colorStep = (colorStart - colorEnd) / (graphSegments - 1);
mapValue = map(value, valueMin, valueMax, 0, graphSegments);
tft.fillRoundRect(posX, posY, ((barWidth + barGap) * graphSegments), barLength, rectRadius, colorBackground);
//tft.drawLine(posX + 1, posY + (barLength / 2 ), posX + (barWidth + barGap)*graphSegments, posY + (barLength / 2 ), ILI9341_AQUA);
for (int x = 0; x < graphSegments; x++) {
Serial.println(x);
if (mapValue >= x) {
tft.fillRoundRect(posX + (x * (barWidth + barGap)), posY, barWidth, barLength, rectRadius, colorStart - (x * colorStep));
} else if (mapValue < graphSegments ) {
tft.fillRect(posX + (x * (barWidth + barGap)), posY + barLength / 2 - 4 + 2, barWidth, 4, colorStart - (x * colorStep));
//tft.fillRoundRect(posX + (x * (barWidth + barGap)), posY, barWidth, barLength, rectRadius, colorBackground);
}
}
tft.fillRect(posX, posY + 40, barWidth, barLength, colorStart - (16 * colorStep));
}
void displayAnimations() {
int posX = 30;
int posY = 10;
int lineLength = 100;
int myDelay = 75;
tft.drawLine(posX, posY, lineLength, posY, colorBorder);
tft.drawLine(posX, posY + 3, lineLength, posY + 3, colorBorder);
//tft.setPixelSize(2);
for (int x = 0; x < lineLength; x++) {
tft.drawPixel(posX + x, posY + 1, ILI9341_RED);
tft.drawPixel(posX + x, posY + 2, ILI9341_RED);
tft.drawPixel(posX + x + 1, posY + 1, ILI9341_RED);
tft.drawPixel(posX + x + 1, posY + 2, ILI9341_RED);
delay(myDelay);
tft.drawPixel(posX + x, posY + 1, ILI9341_BLACK);
tft.drawPixel(posX + x, posY + 2, ILI9341_BLACK);
tft.drawPixel(posX + x + 1, posY + 1, ILI9341_BLACK);
tft.drawPixel(posX + x + 1, posY + 2, ILI9341_BLACK);
//delay(myDelay);
}
}
void displayPowerMeter(int posX, int posY, int valueMin, int valueMax, int value, bool horizontal, bool displayMinMax) {
int length = 90;
int width = 15;
uint16_t colorSeg1 = 0xAE3F ;
uint16_t colorSeg2 = 0x968B;
uint16_t colorSeg3 = 0xB6F1;
uint16_t colorSeg4 = 0xCF56;
uint16_t colorSeg5 = 0xF760;
uint16_t colorSeg6 = 0xFFE8;
uint16_t colorSeg7 = 0xFE2F;
uint16_t colorSeg8 = 0xFD31;
uint16_t colorSeg9 = 0xFB0A;
uint16_t colorCursor = 0xD2BF;
int segLength = length / 9;
int cursorPos = 0;
if (horizontal) {
tft.drawRoundRect(posX, posY, length, width, 15, colorBorder );
tft.fillRoundRect(posX + 2, posY + 1, segLength, width - 2, 15, colorSeg1 );
tft.fillRect(posX + 4, posY + 1, segLength - 2, width - 2, colorSeg1 );
tft.fillRect(posX + 2 + segLength * 1, posY + 1, segLength, width - 2, colorSeg2 );
tft.fillRect(posX + 2 + segLength * 2, posY + 1, segLength, width - 2, colorSeg3 );
tft.fillRect(posX + 2 + segLength * 3, posY + 1, segLength, width - 2, colorSeg4 );
tft.fillRect(posX + 2 + segLength * 4, posY + 1, segLength, width - 2, colorSeg5 );
tft.fillRect(posX + 2 + segLength * 5, posY + 1, segLength, width - 2, colorSeg6 );
tft.fillRect(posX + 2 + segLength * 6, posY + 1, segLength, width - 2, colorSeg7 );
tft.fillRoundRect(posX + 1 + segLength * 8 - 2, posY + 1, segLength, width - 2, 15, colorSeg9 );
tft.fillRect(posX + 2 + segLength * 7, posY + 1, segLength, width - 2, colorSeg8 );
//tft.fillRect(posX + segLength * 8, posY + 1, segLength - 6, width - 2, colorSeg9 );
cursorPos = map(value, valueMin, valueMax, 0, length * 0.95);
//tft.drawRect(posX + cursorPos, posY, length / 12, width, colorCursor);
tft.fillTriangle(posX + cursorPos - 4, posY + width - 3, posX + cursorPos + 3, posY + width - 3, posX + cursorPos, posY + +width - 8, colorBackground);
} else {
length = 15;
width = 90;
tft.drawRoundRect(posX, posY, length, width, 15, colorBorder );
tft.fillRoundRect(posX + 2, posY + 2, segLength + 1, length - 2, 15, colorSeg9 );
tft.fillRect(posX + 2, posY + 6, segLength + 1, length - 2, colorSeg9 );
tft.fillRect(posX + 2, posY + segLength * 1, segLength + 1, length - 5, colorSeg8 );
tft.fillRect(posX + 2, posY + segLength * 2, segLength + 1, length - 5, colorSeg7 );
tft.fillRect(posX + 2, posY + segLength * 3, segLength + 1, length - 5, colorSeg6 );
tft.fillRect(posX + 2, posY + segLength * 4, segLength + 1, length - 5, colorSeg5 );
tft.fillRect(posX + 2, posY + segLength * 5, segLength + 1, length - 5, colorSeg4 );
tft.fillRect(posX + 2, posY + segLength * 6, segLength + 1, length - 5, colorSeg3 );
tft.fillRoundRect(posX + 2, posY + segLength * 8 - 4, segLength + 1, length - 3, 15, colorSeg1 );
tft.fillRect(posX + 2, posY + segLength * 7, segLength + 1, length - 5, colorSeg2 );
//tft.fillRect(posX + 1 + segLength * 2, posY + 1, segLength, width - 2, colorSeg3 );
//tft.fillRect(posX + 1 + segLength * 3, posY + 1, segLength, width - 2, colorSeg4 );
//tft.fillRect(posX + 1 + segLength * 4, posY + 1, segLength, width - 2, colorSeg5 );
//tft.fillRect(posX + 1 + segLength * 5, posY + 1, segLength, width - 2, colorSeg6 );
//tft.fillRect(posX + 1 + segLength * 6, posY + 1, segLength, width - 2, colorSeg7 );
//tft.fillRect(posX + 1 + segLength * 7, posY + 1, segLength, width - 2, colorSeg8 );
//tft.fillRoundRect(posX + segLength * 8, posY + 1, segLength - 2, width - 2, 15, colorSeg9 );
//tft.fillRect(posX + segLength * 8, posY + 1, segLength - 6, width - 2, colorSeg9 );
cursorPos = map(value, valueMax, valueMin, 0, width * 0.95) + 5;
//tft.drawRect(posX, posY + cursorPos, length, 2, colorCursor);
tft.fillTriangle(posX + 2, posY + cursorPos - 3, posX + 2, posY + cursorPos + 3, posX + 7, posY + cursorPos, colorBackground);
}
}
void displayBattery(int posX, int posY) {
int batterySOC = 79;
int batterySOC_P = 79;
//int x = 28; // X-coordinate of the top-left corner of the Battery
//int y = 102; // Y-coordinate of the top-left corner of the Battery
int width = 56; // Width of the Battery
int height = 45; // Height of the Battery
//char powerFlow[] = ox
uint16_t colorSeg1 = ILI9341_GREEN;
uint16_t colorSeg2 = ILI9341_GREEN;
uint16_t colorSeg3 = ILI9341_GREEN;
uint16_t colorSeg4 = ILI9341_GREEN;
uint16_t colorSeg5 = ILI9341_GREEN;
char buff1[5];
dtostrf(batterySOC, 3, 0, buff1); // Copy myBatterySOC to buff1
sprintf(buff1, "%s%%", buff1);
//Move next line to global and reset as needed
if (batterySOC > batterySOC_P) {
colorBattery = ILI9341_GREEN;
} else if (batterySOC < batterySOC_P) {
colorBattery = ILI9341_RED;
}
int posSOC = 5; //calulate the Position of the Battery SOC Text
if (batterySOC < 100) {
posSOC = 2;
}
if (batterySOC > 95) {
colorSeg5 = ILI9341_GREEN;
} else if (batterySOC > 89) {
colorSeg5 = ILI9341_YELLOW;
} else if (batterySOC > 79) {
colorSeg5 = ILI9341_ORANGE;
} else if (batterySOC > 69) {
colorSeg4 = ILI9341_YELLOW;
colorSeg5 = ILI9341_BLACK;
} else if (batterySOC > 59) {
colorSeg4 = ILI9341_ORANGE;
colorSeg5 = ILI9341_BLACK;
} else if (batterySOC > 49) {
colorSeg3 = ILI9341_YELLOW;
colorSeg4 = ILI9341_BLACK;
colorSeg5 = ILI9341_BLACK;
} else if (batterySOC > 39) {
colorSeg3 = ILI9341_YELLOW;
colorSeg4 = ILI9341_BLACK;
colorSeg5 = ILI9341_BLACK;
} else if (batterySOC > 29) {
colorSeg2 = ILI9341_YELLOW;
colorSeg3 = ILI9341_BLACK;
colorSeg4 = ILI9341_BLACK;
colorSeg5 = ILI9341_BLACK;
} else if (batterySOC < 29) {
colorSeg1 = ILI9341_RED;
colorSeg2 = ILI9341_RED;
colorSeg3 = ILI9341_BLACK;
colorSeg4 = ILI9341_BLACK;
colorSeg5 = ILI9341_BLACK;
}
tft.fillRoundRect(posX - 4, posY + 15, 6, 12, 2, colorBorder); //Battery Terminal
tft.fillRoundRect(posX, posY, width, height, 2, colorBorder);
tft.fillRoundRect(posX + 2, posY + 2, width - 4, height - 4, 2, colorBackground);
tft.fillRoundRect(posX + 4, posY + 4, 8, height - 8, 2, colorSeg5); //5st segment
tft.fillRoundRect(posX + 4 + 2 + 8 * 1, posY + 4, 8, height - 8, 2, colorSeg4); //4st segment
tft.fillRoundRect(posX + 4 + 4 + 8 * 2, posY + 4, 8, height - 8, 2, colorSeg3); //3st segment
tft.fillRoundRect(posX + 4 + 6 + 8 * 3, posY + 4, 8, height - 8, 2, colorSeg2); //2st segment
tft.fillRoundRect(posX + 4 + 8 + 8 * 4, posY + 4, 8, height - 8, 2, colorSeg1); //1st segment
tft.drawRoundRect(posX + 4, posY + 4, 8, height - 8, 2, colorBorder); //5st segment
tft.drawRoundRect(posX + 4 + 2 + 8 * 1, posY + 4, 8, height - 8, 2, colorBorder); //4st segment
tft.drawRoundRect(posX + 4 + 4 + 8 * 2, posY + 4, 8, height - 8, 2, colorBorder); //3st segment
tft.drawRoundRect(posX + 4 + 6 + 8 * 3, posY + 4, 8, height - 8, 2, colorBorder); //2st segment
tft.drawRoundRect(posX + 4 + 8 + 8 * 4, posY + 4, 8, height - 8, 2, colorBorder); //1st segment
printTextToTFT(ILI9341_WHITE, 1, posX + posSOC, posY - 8, true, buff1);
}
void printTextToTFT(uint16_t textColor, int textSize, int textX, int textY, bool backgroundFill, char textPrint[]) {
tft.setCursor(textX, textY);
if (backgroundFill) {
tft.setTextColor(textColor, colorBackground);
} else {
tft.setTextColor(textColor);
}
tft.setTextSize(textSize);
tft.print(textPrint);
}
void printTextToTFT(uint16_t textColor, int textSize, int textX, int textY, bool backgroundFill, char textPrint[], GFXfont* currentFont) {
if (backgroundFill) {
tft.setTextColor(textColor, colorBackground);
} else {
tft.setTextColor(textColor);
}
tft.setFont(currentFont);
tft.setCursor(textX, textY);
tft.setTextSize(textSize);
tft.print(textPrint);
tft.setFont();
}
void loop() {}