Bar graph or Progress Bar Help #1855
Unanswered
Seaha4487
asked this question in
Q&A - General
Replies: 1 comment
-
The progress bar code is for an increasing percentage only, see here: The function does not handle "negative" progress. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey Guys sorry to bother you but i am trying since two days to get my progress bar working.
I have a code wich receives Mqtt Values and show them on the display and this works. Now i want a Progress bar that shows me the value in percent. I am using the tft_efex library but the problem is that the graph shows perfect if it receives a incresed value but if the value decresed the bar didnt decrease. And i dont know why.
Also i need the graph shows up values with decimals like 5.5 but i map the value and then it gives out just 5 insted of 5,5.
Could anybody help me please.
`#include <TFT_eFEX.h>
#include <ESP8266WiFi.h>
#include <WiFiManager.h>
#include <PubSubClient.h>
#include <TFT_eSPI.h>
#include <DoubleResetDetector.h>
#include "bilder.h"
#include"font.h"
#define RED2GREEN 5
#define DRD_TIMEOUT 10
#define DRD_ADDRESS 0
DoubleResetDetector drd(DRD_TIMEOUT, DRD_ADDRESS);
TFT_eSPI tft = TFT_eSPI();
TFT_eFEX fex = TFT_eFEX(&tft);
const char* mqtt_server = "test.mosquitto.org";
const char* mqttTopic_RaumTemp = "Loxone/RaumTemp";
const char* mqttTopic_PoolTemp = "Loxone/PoolTemp";
const char* mqttTopic_PV = "Loxone/PV";
const char* mqttTopic_ID3 = "Loxone/ID3";
const char* mqttTopic_Cayenne = "Loxone/Cayenne";
WiFiClient espClient;
PubSubClient client(espClient);
void callback(String topic, byte* payload, unsigned int length) {
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
String data;
for (int i = 0; i < length; i++) {
//Serial.print((char)payload[i]);
data += (char)payload[i];
}
/*********************************************************************************************/
if (topic == "Loxone/RaumTemp")
{
Serial.println(topic);
uint16_t box_x = 1;
uint16_t box_y = 20;
uint16_t box_w = 45;
uint16_t box_h = 17;
tft.setTextColor(TFT_WHITE);
//tft.setTextFont(GLCD);
tft.setFreeFont(&Open_Sans_Bold_20);
tft.fillRect(box_x, box_y, box_w, box_h, TFT_BLACK);
tft.drawString(data,box_x, box_y);
Serial.println(data);
}
if (topic == "Loxone/PoolTemp")
{
Serial.println(topic);
uint16_t box_x = 76;
uint16_t box_y = 20;
uint16_t box_w = 45;
uint16_t box_h = 17;
tft.setTextColor(TFT_WHITE);
tft.setFreeFont(&Open_Sans_Bold_20);
tft.fillRect(box_x, box_y, box_w, box_h, TFT_BLACK);
tft.drawString(data,box_x, box_y);
Serial.println(data);
}
if (topic == "Loxone/Cayenne")
{
Serial.println(topic);
uint16_t box_x = 76;
uint16_t box_y = 65;
uint16_t box_w = 45;
uint16_t box_h = 17;
tft.setFreeFont(&Open_Sans_Bold_20);
tft.fillRect(box_x, box_y, box_w, box_h, TFT_BLACK);
tft.drawString(data,box_x, box_y);
Serial.println(data);
}
if (topic == "Loxone/ID3")
{
Serial.println(topic);
uint16_t box_x = 4;
uint16_t box_y = 65;
uint16_t box_w = 45;
uint16_t box_h = 17;
tft.setFreeFont(&Open_Sans_Bold_20);
tft.fillRect(box_x, box_y, box_w, box_h, TFT_BLACK);
tft.drawString(data,box_x, box_y);
Serial.println(data);
}
if (topic == "Loxone/PV")
{
Serial.println(topic);
//float dataFloat = data.toFloat();
//float data1 = data.toInt();
float data1 = data.toFloat()*10;
data1 = map(data1, 0, 10, 0, 100);
float data2 = data1 / 100;
}
/***********************************************************************************/
}
void reconnect() {
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
String clientId = "ESP8266Client-";
clientId += String(random(0xffff), HEX);
if (client.connect(clientId.c_str())) {
Serial.println("connected");
/**************************************************************/
client.subscribe(mqttTopic_RaumTemp);
client.subscribe(mqttTopic_PoolTemp);
client.subscribe(mqttTopic_ID3);
client.subscribe(mqttTopic_Cayenne);
client.subscribe(mqttTopic_PV);
}
}
void setup() {
pinMode(BUILTIN_LED, OUTPUT); // Initialize the BUILTIN_LED pin as an output
Serial.begin(115200);
WiFiManager wifiManager;
tft.begin();
tft.setRotation(2);
tft.fillScreen(TFT_BLACK);
delay(2000);
tft.fillScreen(TFT_WHITE);
tft.setTextColor(TFT_BLACK);
tft.setCursor(10, 2);
tft.print("Double reset withen 10 seconds");
if (drd.detectDoubleReset()) {
tft.fillScreen(TFT_WHITE);
tft.setCursor(10, 2);
tft.print("Double reset detected: Connect to open wifi MQTT-Display and open IP: 192.168. 4.1 to configure WiFi");
Serial.println("Double Reset Detected");
digitalWrite(LED_BUILTIN, HIGH);
wifiManager.resetSettings();
} else {
Serial.println("No Double Reset Detected");
digitalWrite(LED_BUILTIN, LOW);
}
Serial.println("Connecting");
wifiManager.autoConnect("MQTT-Display");
Serial.println("Connected.");
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
tft.fillScreen(TFT_BLACK);
tft.drawBitmap(0, 0, logo, 128, 128, TFT_WHITE);
delay(3000);
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_WHITE);
tft.drawFastHLine(0, 43, 128, TFT_WHITE);
tft.drawFastHLine(0, 42, 128, TFT_WHITE);
tft.drawFastHLine(0, 86, 128, TFT_WHITE);
tft.drawFastHLine(0, 87, 128, TFT_WHITE);
tft.setSwapBytes(true);
tft.pushImage(2,90,25,40,pv);
tft.setSwapBytes(true);
tft.pushImage(56,0,16,40,temp1);
tft.setSwapBytes(true);
tft.pushImage(55,46,18,38,fan);
tft.setCursor(10, 2);
tft.print("Aussen");
tft.setCursor(85, 2);
tft.print("Pool");
tft.setCursor(80, 48);
tft.print("Cayenne");
tft.setCursor(14, 48);
tft.print("ID.3");
tft.setCursor(110, 110);
tft.print("kW");
tft.drawCircle(49, 18, 2, TFT_WHITE); //Xpos,Ypos,r,Farbe
tft.drawCircle(124, 18, 2, TFT_WHITE); //Xpos,Ypos,r,Farbe
Serial.println("setup done");
}
void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();
delay(500);
drd.loop();
}`
Beta Was this translation helpful? Give feedback.
All reactions