Start a new topic

Real time fader arduino

Hello,
I can not get the value of a slider in real time.
I only receive the value when I touch or release.
But when I change the value of the slider it appears well on the screen
But is not transmitted to the arduino
How to do it?
 
Other disagreement:
The slider is in absolute mode. That is, when you touch the slider at a level it takes the value or touches it.
Would it be possible to make relative slider?
 
thank you

------------------------  

Gerry Kropf

replied 17 hours ago

are you sure the values are not send? Or does your Arduino logic just only not catch the incoming data due to its speed they are send out while move?


I am not aware of any slider, which works in a relative offset mode. Sliders per se are not designed for wipe-alike input, sorry. Nevertheless, you can use them in such a way by code ... there are examples out for this ...

https://www.itead.cc/blog/advanced-application-3-slide-to-unlock-and-battery-charging-progress-project/


btw. the chance to get a Nextion related answer is much better, when you post in our Nextion Forum ... 


Patrick Martin

said 6 hours ago
The issue with trying to get real-time slide is that TouchMove can not send out as fast as you can move.  This will result in your serial experiencing buffer overruns.

You are more than welcome to explore this by putting print/printh statements in the touch move event in your HMI and then catch this via your Arduino - and this will quickly allow you to see why it is not implemented by default.

In TouchMove
printh 65 99 01 01 FF FF FF
print h0.val

In Arduino
  NexSlider movecatcher = NexSlider(99,1,"virtual");
  add &movecatcher to nex_listen_list
  add movecatcher.attachPush(catchslide, &movecatcher); to setup
  create catchslide function

void catchslide(void *ptr) {
   uint32_t slideval;
   recvRetNumber(&slideval,100);
   // do what you like with current slide value
}


Fading is a coding technique
 - last known value
 - incoming new value on release
 - code to implement changes incrementally
As such would not be a harsh jump in levels

------------------------

Ok here is my code
But I do not understand why it does not work
The only return I have in com  is this:

recvRetCommandFinished ok
recvRetCommandFinished ok
setup done
[1674:0,1,h0]
[1674:0,1,h0]
[1674:0,1,h0]
[1674:0,1,h0]
When I release the fader :
[1674:0,1,h0]

[code]
#include "Nextion.h"
NexSlider h0 = NexSlider(0, 1, "h0");
NexSlider movecatcher = NexSlider(99,1,"virtual");
 
NexTouch *nex_listen_list[] =
{
    &h0,
    &movecatcher,
    NULL
};
 
void setup() {
  // put your setup code here, to run once:
nexInit();
movecatcher.attachPush(catchslide, &movecatcher);
dbSerialPrintln("setup done");
}
 
void loop() {
  // put your main code here, to run repeatedly:
 nexLoop(nex_listen_list);
}
 
void catchslide(void *ptr) {
  dbSerialPrintln("catchslide");
   uint32_t slideval;
   recvRetNumber(&slideval,100);
   // do what you like with current slide value
   dbSerialPrintln("slideval = ");
   dbSerialPrintln(slideval);
}
 
void h0PopCallback(void *ptr) {
  dbSerialPrintln ("pop");
    uint32_t number = 0;
    char temp[10] = {0};
   
    dbSerialPrintln("h0PopCallback");
 
    h0.getValue(&number);
   dbSerialPrintln("h0 = ");
   dbSerialPrintln(number);
 
 
}
[/code]
thank you
HMI
(56.7 KB)

Main reason it doesn't work is expecting cut copy paste and not checking

- printh 65 99 01 01 FF FF FF

  is setting up for virtual(there is no such page 0x99) component touch event

- hex 99 is is decimal 153

- therefore proper is

     NexSlider movecatcher = NexSlider(0x99,1,"virtual");  or

     NexSlider movecatcher = NexSlider(153,1,"virtual");

- NexSlider movecatcher = NexSlider(99,1,"virtual");

  requires a printh 65 63 01 01 FF FF FF


1 person likes this

Very good, now I have that:


recvRetCommandFinished ok

recvRetCommandFinished ok

setup done

[1640:99,1,virtual]

catchslide

recvRetNumber err

slideval =

1

[1640:99,1,virtual]

catchslide

recvRetNumber err

slideval =

1

[1640:99,1,virtual]

catchslide

recvRetNumber err

slideval =

1

The value of slideval is always 1?


So the catchslide void works but why does the value of h (slideval) not change?

And why h0PopCallback does not work?

thank you

Hey Guys


I tested this and it is capable of catching/decoding all output from Nextion.


The resolution will ultimately depend on how fast the slider is moved.


Nextion side is slowed with the 'cov' operation, so the code for the slider (Touch Move event) is.... 

cov h0.val,va0.txt,0
print va0.txt
print ">"

  Arduino...... 

static uint8_t receivedNumber = 0;

void processInput () {

    byte c = Serial.read ();

    switch (c)
    {

    case '>':

      Serial.print("Rec' Num: ");
      Serial.println(receivedNumber);
      receivedNumber = 0;

      break;

    case '0' ... '9':
      receivedNumber *= 10;
      receivedNumber += c - '0';

      break;

    } // end of switch  
}  // end of processInput

void setup () {
  Serial.begin (115200);
  Serial.println ("Starting Test ...");
} 

void loop () {

  while (Serial.available ())
    processInput ();
} 

 

 

This is an alternative using the 4 byte print h0.val method, the downside is you need to send 5 bytes (inc.delimiter) for every increment. On the plus, Arduino has only to add byte values (will work from 0 - 254 slider range).

  

void processInput () {
  
    byte c = Serial.read ();

    if (c == '~') {//Delimiter 'value' must be outside the slider range
      Serial.print("Rec' Num: ");
      Serial.println(receivedNumber);
      receivedNumber = 0;
    }
    else {
      receivedNumber += c;//For little endian first byte is the 'value' followed by adding 3 zero values.
    }
} 

   


1 person likes this

OK

BUT I WORK VERY SLOWLY

WHY MUST BE CONVERTED H0.VAL IN TXT

WHY DO NOT SEND IT IN .VAL


indev2 offered alternatives via straight code.

It can be received via .val as I already pointed out at first.

And depending on what ELSE you have competing for processing time

it can be slow, but itself it is fairly quick


You must balance wants and needs to processing capabilities you have

Login or Signup to post a comment