Start a new topic

Arduino how to increase value while precionado Touch Event with Nextion?

Hello friends, I wonder if anyone knows how to increment a value to a variable when presionado Touch Event with Arduino?
  For the Touch Event of nextion only increases a value per event!
  I'm doing a project of a soldering station with LCD Nextion,
  More to increase temperatuara to 350C °, I precisso precionar 350 times to give the value, I do not want that!
  Anybody know?


In the attached file I created a timer with a time of 250 and set it to not enabled.
Then on pressing b0, I enable the timer and add 1 to the value n0.
If you continue to hold b0 after 250ms it will start adding 10 to the n0.val
On release of b0 it disables the timer again.

You could do this in reverse to decrease the value.

 

HMI
(9.32 KB)

1 person likes this
thank you for attention, but does Arduino only read up to 255 because, when passing this value gives error, it is to read the value above 255 350 for example
look at the test code;


 */
  int array[8];
  int i =0;
 


void setup() {
  // initialize serial:
  Serial.begin(9600);
  // reserve 200 bytes for the inputString:

}

void loop() {
  //serialEvent();
  readDataSimple2 ();

}

void readDataSimple2 () {

  while (Serial.available() > 0) {
  for ( i = 1 ; i < 8; i++) {
  array[i] =  Serial.read();
  Serial.println(array[i]);
   

  delay(20);
  }
   

  array[7] = '\0';
  int pageNumber = array[2];
  int componentNumber = array[3];
  int pressEvent = array[4];
  int numericalData = array[5];
  Serial.print("pageNumber: ");
  Serial.println(pageNumber);
  Serial.print("componentNumber: ");
  Serial.println(componentNumber);
  Serial.print("pressEvent: ");
  Serial.println(pressEvent);
  Serial.print("numericalData: ");
   
   }
}
does anyone know how to do?
HMI

estation.png

 

/returns the 4-byte hexadecimal data of value 0x71 0x5e 0x01 0x00 0x000xff 0xff 0xff

 

0x71 0x5e 0x01 0x00 0x000xff 0xff 0xff

converter for decimal 0x015e = 350 decimal

0x71 0x5e 0x01 0x00 0x00 0xff 0xff 0xff


This is called little endian byte order.  The 4 bytes make up a 32 bit number, the first byte received in the number (0x5E) is the smallest or least significant byte, the final byte of 0x00 is the most significant byte.


1st byte 5E 

2nd byte 01

3rd byte 00

4th byte 00


4th x 16777216 + 3rd x 65536 + 2nd x 256 + 1st x 1

           0                         0                  256            94


0x71 return code tells you to expect 4 numeric bytes followed by three 0xFF terminating bytes

Now you know that you need to capture all four bytes, and how to combine them into the one final number = 350


1 person likes this
Thank you please help me because I can not do combine into Them the one end number!

 

I can make a few suggestions, I don't have code to offer you.

You will have to learn how to arrange your code so that it functions the way you want.


Perhaps

long combining_number = array[1]+array[2]*256+array[3]*65536+array[4]*1677216;

or

unsigned long combining_number = array[1]+array[2]*256+array[3]*65536+array[4]*1677216;


each byte number from 0 to 255 in the array is combined by multiplying each byte by the value its position holds.

Hello everyone, thank you very much for the help, I made this code to read the Nextion button and receive the 0 to 480, only that it presents error when it changes from 255 to 256 and 260 etc. Can someone help me fix this error? See the code.


 */
 int array[8];
 int dispTemvalor =0 ;

void setup() {
  // initialize serial:
  Serial.begin(9600);
  //Serial.println(dispTemvalor);
 
}

void loop() {

Serial.println(dispTemvalor);
   
  ReadSerial();
   
}
//**********************************//****************************
  int ReadSerial ()
  {
  int i=0;
   int b =0;
  while (Serial.available() > 1)
  {
      for ( i = 1 ; i <16; i++) {
      array[i] =  Serial.read();
  Serial.println(array[i]);
  delay(20);
      }

    if(array[2]>1 && array[3]==0){
      dispTemvalor = array[2];
      }

    if(array[2]== 0 && array[3]==1){
  dispTemvalor += array[2] + array[3];
      }

    if(array[2]>0 && array[3]==1){
  b = array[2] + array[3];
  dispTemvalor +=b;
  }  
  }
  }

 

The first error in the code Is that when above 255,

array[3] should not be added to the array[2] value

   array[2] is a multiple of 1

   array[3] is a multiple of 256.

   array[3] is a multiple of 65536.

   array[3] is a multiple of 16777216.


therefore:

   b = array[5]*16777216+array[4]*65536+array[3]*256+array[2];

   dispTemvalor = b;


1 person likes this
Login or Signup to post a comment