sstaub / NextionX2

Library for Nextion displays
MIT License
13 stars 5 forks source link

Touch trigger isn't fired when checking IO #9

Closed lenkaiser closed 11 months ago

lenkaiser commented 11 months ago

Hi,

I'm just here for advice this is not really a bug in Nextion X2 library. What I experience is that when I add some additional logic to the loop-method it doesn't trigger my btnStepUp method any more. When I disable the sensor check it does work. I presume it's because the Nextion display already sent the data but the arduino is not listening because it's busy checking IO ports. Do you have experience on how to handle this?

#include "NextionX2.h"
#include "SoftwareSerial.h"
#include <ezButton.h>

SoftwareSerial SerialNextion(PA10, PA9);
NextionComPort nextion;

#define topPin PB10

NextionComponent btUp(nextion, 0, 8);
ezButton topSensor(topPin);

void setup()
{
  nextion.begin(SerialNextion);

  pinMode(LED_BUILTIN, OUTPUT);

  btUp.touch(btnStepUp);
}

bool initDone = false;
void loop()
{
  nextion.update();

  /// If this is enabled nextion touch trigger doesn't work anymore
  // topSensor.loop();
  // if (dir == CCW && topSensor.getState() == LOW)
  // {
  //   topPosition = stepper.currentPosition();
  //   dir = CW;
  // }

  // I also tried to add another update() at the end of the loop but no difference
  // nextion.update();
}

void btnStepUp()
{
  digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
sstaub commented 11 months ago

Maybe the ezButton blocks the loop(). Use the discussion forum please.