hola buenas a todos soy nuevo en el foro y en esto de programar en C++ estoy empezando a dar los primeros pasos y me he adentrado en hacer un proyecto el cual pueda gestionar varias salidas digitales, un par de sondas y unos niveles.
Actualmente tengo dos problemas
1- Despues de realizar la programacion de 3 salidas digitales aun no esta terminado en total serian 6 salidas, he encontrado que al cambiar de pagina en la Nextion se activan estas salidas cuando no las he activado con el boton de estado dual y no entiendo el motivo si podeis orientarme en como solucionar este fallo seria de gran ayuda
2- Despues de hacer prueba en aislado la parte de los botones Rojo y Azul para incrementar o restar a n3 un valor este funciona, cuando lo uno todo en el loop con las demas funciones este deja de funcionar
#include <doxygen.h>
#include <NexButton.h>
#include <NexCheckbox.h>
#include <NexConfig.h>
#include <NexCrop.h>
#include <NexDualStateButton.h>
#include <NexGauge.h>
#include <NexGpio.h>
#include <NexHardware.h>
#include <NexHotspot.h>
#include <NexNumber.h>
#include <NexObject.h>
#include <NexPage.h>
#include <NexPicture.h>
#include <NexProgressBar.h>
#include <NexRadio.h>
#include <NexRtc.h>
#include <NexScrolltext.h>
#include <NexSlider.h>
#include <NexText.h>
#include <NexTimer.h>
#include <Nextion.h>
#include <NexTouch.h>
#include <NexUpload.h>
#include <NexVariable.h>
#include <NexWaveform.h>
#define RT0 10000 // Ω
#define B 3977 // K
#define VCC 5 //Supply voltage
#define R 10000 //R=10KΩ
float RT, VR, ln, TX, T0, VRT;
float sensorPin = A0; // seleccionar la entrada para el sensor
float sensorValue; // variable que almacena el valor raw (0 a 1023)
int progress = 0; // variable de proceso barra
int setpoint = 22;
NexDSButton bt0 = NexDSButton(0, 1, "bt0");
NexDSButton bt1 = NexDSButton(0, 2, "bt1");
NexDSButton bt2 = NexDSButton(0, 3, "bt2");
NexButton b2 = NexButton(2, 3, "b2");
NexButton b1 = NexButton(2, 2, "b1");
NexNumber n1 = NexNumber(2, 5, "n1" );
NexNumber n0 = NexNumber(2, 4, "n0" );
NexNumber n2 = NexNumber(2, 6, "n2" );
NexNumber n3 = NexNumber(2, 7, "n3" );
NexProgressBar j0(0, 1, "j0");
char buffer[100] = {0};
NexTouch *nex_listen_list[] =
{
&b2,
&b1,
&bt0,
&bt1,
&bt2,
NULL
};
void b2PushCallback(void *ptr)
{
setpoint = setpoint + 1;
Serial.print("n3.val=");
Serial.print(setpoint);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
void b1PushCallback(void *ptr)
{
setpoint = setpoint - 1;
Serial.print("n3.val=");
Serial.print(setpoint);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
void setup (void)
{
Serial.begin(9600);
b2.attachPush(b2PushCallback, &b2);
b1.attachPush(b1PushCallback, &b1);
nexInit();
pinMode (13, OUTPUT);
pinMode (12, OUTPUT);
pinMode (11, OUTPUT);
T0 = 25 + 273.15;
}
void loop (void) {
nexLoop(nex_listen_list);
bomba();
rele();
boiler();
sucias();
temperaturaboiler();
}
void sucias () {
sensorValue = analogRead(sensorPin); // realizar la lectura
sensorValue = map(sensorValue, 380, 1000, 0, 100);
if (sensorValue > 1) {
progress = 100;
}
if (sensorValue > 7) {
progress = 90;
}
if (sensorValue > 13) {
progress = 80;
}
if (sensorValue > 17) {
progress = 70;
}
if (sensorValue > 21) {
progress = 60;
}
if (sensorValue > 24) {
progress = 50;
}
if (sensorValue > 30) {
progress = 40;
}
if (sensorValue > 35) {
progress = 30;
}
if (sensorValue > 50) {
progress = 20;
}
if (sensorValue > 90) {
progress = 0;
}
j0.setValue(progress);
n1.setValue(progress);
delay(100);
}
void temperaturaboiler () {
VRT = analogRead(A2); //Acquisition analog value of VRT
VRT = (5.00 / 1023.00) * VRT; //Conversion to voltage
VR = VCC - VRT;
RT = VRT / (VR / R); //Resistance of RT
ln = log(RT / RT0);
TX = (1 / ((ln / B) + (1 / T0))); //Temperature from thermistor
TX = TX - 273.15;
n2.setValue(TX); //Conversion to Celsius
}
void bomba () {
uint32_t botonbomba;
bt0.getValue(&botonbomba);
if (botonbomba) {
digitalWrite(13, HIGH);
}
else {
digitalWrite(13, LOW);
}
}
void rele () {
uint32_t botonrele1;
bt1.getValue(&botonrele1);
if (botonrele1) {
digitalWrite(12, HIGH);
}
else {
digitalWrite(12, LOW);
}
}
void boiler () {
uint32_t botonboiler;
bt0.getValue(&botonboiler);
if (botonboiler) {
digitalWrite(11, HIGH);
}
else {
digitalWrite(11, LOW);
}
}
Me gustaria subir el archivo HMI pero al ser usuario nuevo no me es posible, ante todo muchas gracias a todos los que su intencion sea de ayudar, Un saludo
https://drive.google.com/file/d/1FMD7C0MlBsUSTsvvfjaMoeuViHKgu9RG/view?usp=sharing
Intento compartirlo por drive