Topic: Why does my level indicator go back to 0 bars?
I have a simple map function, using the values from a dht11 sensor, (converted to farenheit as an integer type) that goes like this:
RemoteXY_Handler ();
float TempF = dht.readTemperature(true);//Read Temp in F.
dtostrf (TempF, 11, 1, RemoteXY.text_1);
RemoteXY.level_1 = map(TempF, 65, 75, 0, 100);
RemoteXY.level_1 = constrain(RemoteXY.level_1, 0, 100);
It's supposed to apply the temperature values from 65-75F into a map from 0-100. It works fine until it goes over 75 degrees; the level indicator goes from full to empty, and remains empty above that temperature. Shouldn't it stay full over my desired max temp, especially since i included the map constraint? Am I doing something wrong?
Here is all the code:
#include <DHT.h>
#include <DHT_U.h>
#define DHTPIN 15
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
// RemoteXY select connection mode and include library
#define REMOTEXY_MODE__ESP32CORE_WIFI_CLOUD
#include <WiFi.h>
#include <RemoteXY.h>
// RemoteXY connection settings
#define REMOTEXY_WIFI_SSID "router"
#define REMOTEXY_WIFI_PASSWORD "password"
#define REMOTEXY_CLOUD_SERVER "cloud.remotexy.com"
#define REMOTEXY_CLOUD_PORT 6376
#define REMOTEXY_CLOUD_TOKEN "138c72411d572af403ce616b********"
// RemoteXY configuration
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
{ 255,0,0,32,0,101,0,10,12,0,
66,0,4,22,18,39,36,12,66,0,
79,22,17,39,204,12,68,50,25,17,
51,42,8,36,135,86,97,114,105,97,
98,108,101,32,49,0,86,97,114,105,
97,98,108,101,32,50,0,67,0,4,
16,18,5,2,26,11,67,0,79,16,
17,5,2,26,11,129,0,4,8,23,
6,36,84,101,109,112,32,70,58,0,
129,0,65,8,33,6,6,72,117,109,
105,100,105,116,121,32,37,0 };
// this structure defines all the variables and events of your control interface
struct {
// output variables
int8_t level_1; // =0..100 level position
int8_t level_2; // =0..100 level position
float TempHumidityHistory_var1;
float TempHumidityHistory_var2;
char text_1[11]; // string UTF8 end zero
char text_2[11]; // string UTF8 end zero
// other variable
uint8_t connect_flag; // =1 if wire connected, else =0
} RemoteXY;
#pragma pack(pop)
/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////
void setup()
{
RemoteXY_Init ();
Serial.begin(9600);
dht.begin();
}
void loop()
{
RemoteXY_Handler ();
float TempF = dht.readTemperature(true);//Read Temp in F.
dtostrf (TempF, 11, 1, RemoteXY.text_1);
RemoteXY.level_1 = map(TempF, 65, 75, 0, 100);
RemoteXY.level_1 = constrain(RemoteXY.level_1, 0, 100);
RemoteXY.TempHumidityHistory_var1 = float (TempF);
float Humid = dht.readHumidity();//Read Humidity in %RH.
dtostrf (Humid, 11, 1, RemoteXY.text_2);
RemoteXY.level_2 = map(TempF, 45, 55, 0, 100);
RemoteXY.level_2 = constrain(RemoteXY.level_2, 0, 100);
RemoteXY.TempHumidityHistory_var2 = float (Humid);
// TODO you loop code
// use the RemoteXY structure for data transfer
// do not call delay()
}